Replace all values in one column to 1
Clash Royale CLAN TAG#URR8PPP
up vote
8
down vote
favorite
I have multiple text files containing 12 lines and 3 columns.
Example:
2 6 0.74
42 6 0.58
80 6 0
112 6 0.24
132 6 1
216 6 0.7
342 6 0
390 6 0.21
432 6 0.56
466 6 0.75
524 6 0.6
646 6 0.9
I want to set all the values of the third column to 1 in all lines.
The output should look like this :
2 6 1
42 6 1
80 6 1
112 6 1
132 6 1
216 6 1
342 6 1
390 6 1
432 6 1
466 6 1
524 6 1
646 6 1
Does anyone know a command that can solve this problem?
text-processing awk sed grep replace
add a comment |Â
up vote
8
down vote
favorite
I have multiple text files containing 12 lines and 3 columns.
Example:
2 6 0.74
42 6 0.58
80 6 0
112 6 0.24
132 6 1
216 6 0.7
342 6 0
390 6 0.21
432 6 0.56
466 6 0.75
524 6 0.6
646 6 0.9
I want to set all the values of the third column to 1 in all lines.
The output should look like this :
2 6 1
42 6 1
80 6 1
112 6 1
132 6 1
216 6 1
342 6 1
390 6 1
432 6 1
466 6 1
524 6 1
646 6 1
Does anyone know a command that can solve this problem?
text-processing awk sed grep replace
add a comment |Â
up vote
8
down vote
favorite
up vote
8
down vote
favorite
I have multiple text files containing 12 lines and 3 columns.
Example:
2 6 0.74
42 6 0.58
80 6 0
112 6 0.24
132 6 1
216 6 0.7
342 6 0
390 6 0.21
432 6 0.56
466 6 0.75
524 6 0.6
646 6 0.9
I want to set all the values of the third column to 1 in all lines.
The output should look like this :
2 6 1
42 6 1
80 6 1
112 6 1
132 6 1
216 6 1
342 6 1
390 6 1
432 6 1
466 6 1
524 6 1
646 6 1
Does anyone know a command that can solve this problem?
text-processing awk sed grep replace
I have multiple text files containing 12 lines and 3 columns.
Example:
2 6 0.74
42 6 0.58
80 6 0
112 6 0.24
132 6 1
216 6 0.7
342 6 0
390 6 0.21
432 6 0.56
466 6 0.75
524 6 0.6
646 6 0.9
I want to set all the values of the third column to 1 in all lines.
The output should look like this :
2 6 1
42 6 1
80 6 1
112 6 1
132 6 1
216 6 1
342 6 1
390 6 1
432 6 1
466 6 1
524 6 1
646 6 1
Does anyone know a command that can solve this problem?
text-processing awk sed grep replace
text-processing awk sed grep replace
edited Feb 6 at 22:40
Jesse_b
10.5k22659
10.5k22659
asked Dec 1 '16 at 9:19
user203269
41113
41113
add a comment |Â
add a comment |Â
6 Answers
6
active
oldest
votes
up vote
14
down vote
awk 'print $1, $2, "1"' inputfile
1
This command prints out the first line in the textfile corrrectly in terminal, but does not make changes in the file...
â user203269
Dec 2 '16 at 12:01
redirect the output to another fileawk 'print $1, $2, "1"' inputfile > newfile
â user1700494
Dec 2 '16 at 13:51
Thanks! It works but only writes out the first line, column 1, 2 and 3. I would like to write out all 12 lines in the same manner :)
â user203269
Dec 2 '16 at 16:30
add a comment |Â
up vote
10
down vote
try
awk
awk '$3=1 ; print ;' oldfile > newfile
$3 = 1
will set third field to 1
sed (here GNU or busybox sed
with its -i
option for in-place editing)
sed -i 's/[0-9.]*$/1/' file
[0-9.]*$
is a sequence from0
to9
and.
up to the end of line.
sed (golfed 4 bytes)
sed -i 's/[^ ]*$/1/' file
[^ ]*$
any char other than space, until end of line.
3
Let's codegolf:sed 's/[^ ]*$/1/'
:->
â Ipor Sircer
Dec 1 '16 at 9:40
Thank you so much! :) The awk seems to work, except for the first line: 2 6 1 6 1 80 6 1 112 6 1 132 6 1 216 6 1 342 6 1 390 6 1 432 6 1 466 6 1 524 6 1 646 6 1 The first line prints the 2nd and 3rd value twice?
â user203269
Dec 1 '16 at 9:44
@user203269 awk version works fine for me (albeit with a formating issue)
â Archemar
Dec 1 '16 at 10:04
3
awk
golfed:awk $3=1
(POSIX but would not work with the awk from the 70s as found in /bin on Solaris)
â Stéphane Chazelas
Dec 1 '16 at 10:10
thatawk
solution is really cool....can you explain pls
â mazs
Dec 1 '16 at 13:59
 |Â
show 3 more comments
up vote
4
down vote
The lines in your expected output seem to end in two space characters and have fields separated by one tab and one space character.
If that's indeed what you want, then you'd need:
awk -v 'OFS=t ' '$3="1 "' < infile > outfile
Or with sed
:
tab=$(printf 't')
sed "
s/[[:blank:]]1,/$tab /g
s/[^[:blank:]]1,[[:blank:]]*$/1 /
s/^[[:blank:]]*//" < infile > outfile
Why the spaces after 1?
â 123
Dec 1 '16 at 15:21
@123, like I said, in the OP's expected output, every line ends in two space characters.
â Stéphane Chazelas
Dec 1 '16 at 15:42
Misread thought you said fields were separated by two space and a tab. my bad.
â 123
Dec 1 '16 at 15:56
Hi Stephane, This awk does the first three values correctly, then it deletes column1 line 2 and continues without making changes..
â user203269
Dec 2 '16 at 12:32
1
@user203269, convert your file from MS-DOS to Unix first.
â Stéphane Chazelas
Dec 2 '16 at 12:50
 |Â
show 1 more comment
up vote
3
down vote
Simply with GNU sed
, using -i
to replace text directly in the file:
sed -i 's:(.*s)(.*s)(.*):121:g' textfile
The columns are matched by regex groups in the parenthesis, reusing them with 1
and 2
and then using a "1" to replace the last group.
In this use case, the solution proposed using awk
is nice and short as well.
add a comment |Â
up vote
2
down vote
this will do the job:
cat textfiles | cut -d' ' -f-2 | sed 's/$/ 1/'
cat file.txt | cut -d' ' -f-2 | sed 's/$/ 1/' 646 6 0.5 1 prints out one line (the last line) in the terminal, but does not change the file.txt...
â user203269
Dec 2 '16 at 12:15
add a comment |Â
up vote
-1
down vote
cat filename | awk -F ' ' '$3=1; print $0' > filename
Could you please edit your post to include more context as to why you feel this is the solution?
â kemotep
Apr 11 at 22:15
add a comment |Â
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
14
down vote
awk 'print $1, $2, "1"' inputfile
1
This command prints out the first line in the textfile corrrectly in terminal, but does not make changes in the file...
â user203269
Dec 2 '16 at 12:01
redirect the output to another fileawk 'print $1, $2, "1"' inputfile > newfile
â user1700494
Dec 2 '16 at 13:51
Thanks! It works but only writes out the first line, column 1, 2 and 3. I would like to write out all 12 lines in the same manner :)
â user203269
Dec 2 '16 at 16:30
add a comment |Â
up vote
14
down vote
awk 'print $1, $2, "1"' inputfile
1
This command prints out the first line in the textfile corrrectly in terminal, but does not make changes in the file...
â user203269
Dec 2 '16 at 12:01
redirect the output to another fileawk 'print $1, $2, "1"' inputfile > newfile
â user1700494
Dec 2 '16 at 13:51
Thanks! It works but only writes out the first line, column 1, 2 and 3. I would like to write out all 12 lines in the same manner :)
â user203269
Dec 2 '16 at 16:30
add a comment |Â
up vote
14
down vote
up vote
14
down vote
awk 'print $1, $2, "1"' inputfile
awk 'print $1, $2, "1"' inputfile
answered Dec 1 '16 at 9:24
user1700494
1,650311
1,650311
1
This command prints out the first line in the textfile corrrectly in terminal, but does not make changes in the file...
â user203269
Dec 2 '16 at 12:01
redirect the output to another fileawk 'print $1, $2, "1"' inputfile > newfile
â user1700494
Dec 2 '16 at 13:51
Thanks! It works but only writes out the first line, column 1, 2 and 3. I would like to write out all 12 lines in the same manner :)
â user203269
Dec 2 '16 at 16:30
add a comment |Â
1
This command prints out the first line in the textfile corrrectly in terminal, but does not make changes in the file...
â user203269
Dec 2 '16 at 12:01
redirect the output to another fileawk 'print $1, $2, "1"' inputfile > newfile
â user1700494
Dec 2 '16 at 13:51
Thanks! It works but only writes out the first line, column 1, 2 and 3. I would like to write out all 12 lines in the same manner :)
â user203269
Dec 2 '16 at 16:30
1
1
This command prints out the first line in the textfile corrrectly in terminal, but does not make changes in the file...
â user203269
Dec 2 '16 at 12:01
This command prints out the first line in the textfile corrrectly in terminal, but does not make changes in the file...
â user203269
Dec 2 '16 at 12:01
redirect the output to another file
awk 'print $1, $2, "1"' inputfile > newfile
â user1700494
Dec 2 '16 at 13:51
redirect the output to another file
awk 'print $1, $2, "1"' inputfile > newfile
â user1700494
Dec 2 '16 at 13:51
Thanks! It works but only writes out the first line, column 1, 2 and 3. I would like to write out all 12 lines in the same manner :)
â user203269
Dec 2 '16 at 16:30
Thanks! It works but only writes out the first line, column 1, 2 and 3. I would like to write out all 12 lines in the same manner :)
â user203269
Dec 2 '16 at 16:30
add a comment |Â
up vote
10
down vote
try
awk
awk '$3=1 ; print ;' oldfile > newfile
$3 = 1
will set third field to 1
sed (here GNU or busybox sed
with its -i
option for in-place editing)
sed -i 's/[0-9.]*$/1/' file
[0-9.]*$
is a sequence from0
to9
and.
up to the end of line.
sed (golfed 4 bytes)
sed -i 's/[^ ]*$/1/' file
[^ ]*$
any char other than space, until end of line.
3
Let's codegolf:sed 's/[^ ]*$/1/'
:->
â Ipor Sircer
Dec 1 '16 at 9:40
Thank you so much! :) The awk seems to work, except for the first line: 2 6 1 6 1 80 6 1 112 6 1 132 6 1 216 6 1 342 6 1 390 6 1 432 6 1 466 6 1 524 6 1 646 6 1 The first line prints the 2nd and 3rd value twice?
â user203269
Dec 1 '16 at 9:44
@user203269 awk version works fine for me (albeit with a formating issue)
â Archemar
Dec 1 '16 at 10:04
3
awk
golfed:awk $3=1
(POSIX but would not work with the awk from the 70s as found in /bin on Solaris)
â Stéphane Chazelas
Dec 1 '16 at 10:10
thatawk
solution is really cool....can you explain pls
â mazs
Dec 1 '16 at 13:59
 |Â
show 3 more comments
up vote
10
down vote
try
awk
awk '$3=1 ; print ;' oldfile > newfile
$3 = 1
will set third field to 1
sed (here GNU or busybox sed
with its -i
option for in-place editing)
sed -i 's/[0-9.]*$/1/' file
[0-9.]*$
is a sequence from0
to9
and.
up to the end of line.
sed (golfed 4 bytes)
sed -i 's/[^ ]*$/1/' file
[^ ]*$
any char other than space, until end of line.
3
Let's codegolf:sed 's/[^ ]*$/1/'
:->
â Ipor Sircer
Dec 1 '16 at 9:40
Thank you so much! :) The awk seems to work, except for the first line: 2 6 1 6 1 80 6 1 112 6 1 132 6 1 216 6 1 342 6 1 390 6 1 432 6 1 466 6 1 524 6 1 646 6 1 The first line prints the 2nd and 3rd value twice?
â user203269
Dec 1 '16 at 9:44
@user203269 awk version works fine for me (albeit with a formating issue)
â Archemar
Dec 1 '16 at 10:04
3
awk
golfed:awk $3=1
(POSIX but would not work with the awk from the 70s as found in /bin on Solaris)
â Stéphane Chazelas
Dec 1 '16 at 10:10
thatawk
solution is really cool....can you explain pls
â mazs
Dec 1 '16 at 13:59
 |Â
show 3 more comments
up vote
10
down vote
up vote
10
down vote
try
awk
awk '$3=1 ; print ;' oldfile > newfile
$3 = 1
will set third field to 1
sed (here GNU or busybox sed
with its -i
option for in-place editing)
sed -i 's/[0-9.]*$/1/' file
[0-9.]*$
is a sequence from0
to9
and.
up to the end of line.
sed (golfed 4 bytes)
sed -i 's/[^ ]*$/1/' file
[^ ]*$
any char other than space, until end of line.
try
awk
awk '$3=1 ; print ;' oldfile > newfile
$3 = 1
will set third field to 1
sed (here GNU or busybox sed
with its -i
option for in-place editing)
sed -i 's/[0-9.]*$/1/' file
[0-9.]*$
is a sequence from0
to9
and.
up to the end of line.
sed (golfed 4 bytes)
sed -i 's/[^ ]*$/1/' file
[^ ]*$
any char other than space, until end of line.
edited Dec 1 '16 at 10:07
Stéphane Chazelas
284k53524862
284k53524862
answered Dec 1 '16 at 9:25
Archemar
19.1k93366
19.1k93366
3
Let's codegolf:sed 's/[^ ]*$/1/'
:->
â Ipor Sircer
Dec 1 '16 at 9:40
Thank you so much! :) The awk seems to work, except for the first line: 2 6 1 6 1 80 6 1 112 6 1 132 6 1 216 6 1 342 6 1 390 6 1 432 6 1 466 6 1 524 6 1 646 6 1 The first line prints the 2nd and 3rd value twice?
â user203269
Dec 1 '16 at 9:44
@user203269 awk version works fine for me (albeit with a formating issue)
â Archemar
Dec 1 '16 at 10:04
3
awk
golfed:awk $3=1
(POSIX but would not work with the awk from the 70s as found in /bin on Solaris)
â Stéphane Chazelas
Dec 1 '16 at 10:10
thatawk
solution is really cool....can you explain pls
â mazs
Dec 1 '16 at 13:59
 |Â
show 3 more comments
3
Let's codegolf:sed 's/[^ ]*$/1/'
:->
â Ipor Sircer
Dec 1 '16 at 9:40
Thank you so much! :) The awk seems to work, except for the first line: 2 6 1 6 1 80 6 1 112 6 1 132 6 1 216 6 1 342 6 1 390 6 1 432 6 1 466 6 1 524 6 1 646 6 1 The first line prints the 2nd and 3rd value twice?
â user203269
Dec 1 '16 at 9:44
@user203269 awk version works fine for me (albeit with a formating issue)
â Archemar
Dec 1 '16 at 10:04
3
awk
golfed:awk $3=1
(POSIX but would not work with the awk from the 70s as found in /bin on Solaris)
â Stéphane Chazelas
Dec 1 '16 at 10:10
thatawk
solution is really cool....can you explain pls
â mazs
Dec 1 '16 at 13:59
3
3
Let's codegolf:
sed 's/[^ ]*$/1/'
:->â Ipor Sircer
Dec 1 '16 at 9:40
Let's codegolf:
sed 's/[^ ]*$/1/'
:->â Ipor Sircer
Dec 1 '16 at 9:40
Thank you so much! :) The awk seems to work, except for the first line: 2 6 1 6 1 80 6 1 112 6 1 132 6 1 216 6 1 342 6 1 390 6 1 432 6 1 466 6 1 524 6 1 646 6 1 The first line prints the 2nd and 3rd value twice?
â user203269
Dec 1 '16 at 9:44
Thank you so much! :) The awk seems to work, except for the first line: 2 6 1 6 1 80 6 1 112 6 1 132 6 1 216 6 1 342 6 1 390 6 1 432 6 1 466 6 1 524 6 1 646 6 1 The first line prints the 2nd and 3rd value twice?
â user203269
Dec 1 '16 at 9:44
@user203269 awk version works fine for me (albeit with a formating issue)
â Archemar
Dec 1 '16 at 10:04
@user203269 awk version works fine for me (albeit with a formating issue)
â Archemar
Dec 1 '16 at 10:04
3
3
awk
golfed: awk $3=1
(POSIX but would not work with the awk from the 70s as found in /bin on Solaris)â Stéphane Chazelas
Dec 1 '16 at 10:10
awk
golfed: awk $3=1
(POSIX but would not work with the awk from the 70s as found in /bin on Solaris)â Stéphane Chazelas
Dec 1 '16 at 10:10
that
awk
solution is really cool....can you explain plsâ mazs
Dec 1 '16 at 13:59
that
awk
solution is really cool....can you explain plsâ mazs
Dec 1 '16 at 13:59
 |Â
show 3 more comments
up vote
4
down vote
The lines in your expected output seem to end in two space characters and have fields separated by one tab and one space character.
If that's indeed what you want, then you'd need:
awk -v 'OFS=t ' '$3="1 "' < infile > outfile
Or with sed
:
tab=$(printf 't')
sed "
s/[[:blank:]]1,/$tab /g
s/[^[:blank:]]1,[[:blank:]]*$/1 /
s/^[[:blank:]]*//" < infile > outfile
Why the spaces after 1?
â 123
Dec 1 '16 at 15:21
@123, like I said, in the OP's expected output, every line ends in two space characters.
â Stéphane Chazelas
Dec 1 '16 at 15:42
Misread thought you said fields were separated by two space and a tab. my bad.
â 123
Dec 1 '16 at 15:56
Hi Stephane, This awk does the first three values correctly, then it deletes column1 line 2 and continues without making changes..
â user203269
Dec 2 '16 at 12:32
1
@user203269, convert your file from MS-DOS to Unix first.
â Stéphane Chazelas
Dec 2 '16 at 12:50
 |Â
show 1 more comment
up vote
4
down vote
The lines in your expected output seem to end in two space characters and have fields separated by one tab and one space character.
If that's indeed what you want, then you'd need:
awk -v 'OFS=t ' '$3="1 "' < infile > outfile
Or with sed
:
tab=$(printf 't')
sed "
s/[[:blank:]]1,/$tab /g
s/[^[:blank:]]1,[[:blank:]]*$/1 /
s/^[[:blank:]]*//" < infile > outfile
Why the spaces after 1?
â 123
Dec 1 '16 at 15:21
@123, like I said, in the OP's expected output, every line ends in two space characters.
â Stéphane Chazelas
Dec 1 '16 at 15:42
Misread thought you said fields were separated by two space and a tab. my bad.
â 123
Dec 1 '16 at 15:56
Hi Stephane, This awk does the first three values correctly, then it deletes column1 line 2 and continues without making changes..
â user203269
Dec 2 '16 at 12:32
1
@user203269, convert your file from MS-DOS to Unix first.
â Stéphane Chazelas
Dec 2 '16 at 12:50
 |Â
show 1 more comment
up vote
4
down vote
up vote
4
down vote
The lines in your expected output seem to end in two space characters and have fields separated by one tab and one space character.
If that's indeed what you want, then you'd need:
awk -v 'OFS=t ' '$3="1 "' < infile > outfile
Or with sed
:
tab=$(printf 't')
sed "
s/[[:blank:]]1,/$tab /g
s/[^[:blank:]]1,[[:blank:]]*$/1 /
s/^[[:blank:]]*//" < infile > outfile
The lines in your expected output seem to end in two space characters and have fields separated by one tab and one space character.
If that's indeed what you want, then you'd need:
awk -v 'OFS=t ' '$3="1 "' < infile > outfile
Or with sed
:
tab=$(printf 't')
sed "
s/[[:blank:]]1,/$tab /g
s/[^[:blank:]]1,[[:blank:]]*$/1 /
s/^[[:blank:]]*//" < infile > outfile
edited Dec 2 '16 at 12:14
answered Dec 1 '16 at 10:22
Stéphane Chazelas
284k53524862
284k53524862
Why the spaces after 1?
â 123
Dec 1 '16 at 15:21
@123, like I said, in the OP's expected output, every line ends in two space characters.
â Stéphane Chazelas
Dec 1 '16 at 15:42
Misread thought you said fields were separated by two space and a tab. my bad.
â 123
Dec 1 '16 at 15:56
Hi Stephane, This awk does the first three values correctly, then it deletes column1 line 2 and continues without making changes..
â user203269
Dec 2 '16 at 12:32
1
@user203269, convert your file from MS-DOS to Unix first.
â Stéphane Chazelas
Dec 2 '16 at 12:50
 |Â
show 1 more comment
Why the spaces after 1?
â 123
Dec 1 '16 at 15:21
@123, like I said, in the OP's expected output, every line ends in two space characters.
â Stéphane Chazelas
Dec 1 '16 at 15:42
Misread thought you said fields were separated by two space and a tab. my bad.
â 123
Dec 1 '16 at 15:56
Hi Stephane, This awk does the first three values correctly, then it deletes column1 line 2 and continues without making changes..
â user203269
Dec 2 '16 at 12:32
1
@user203269, convert your file from MS-DOS to Unix first.
â Stéphane Chazelas
Dec 2 '16 at 12:50
Why the spaces after 1?
â 123
Dec 1 '16 at 15:21
Why the spaces after 1?
â 123
Dec 1 '16 at 15:21
@123, like I said, in the OP's expected output, every line ends in two space characters.
â Stéphane Chazelas
Dec 1 '16 at 15:42
@123, like I said, in the OP's expected output, every line ends in two space characters.
â Stéphane Chazelas
Dec 1 '16 at 15:42
Misread thought you said fields were separated by two space and a tab. my bad.
â 123
Dec 1 '16 at 15:56
Misread thought you said fields were separated by two space and a tab. my bad.
â 123
Dec 1 '16 at 15:56
Hi Stephane, This awk does the first three values correctly, then it deletes column1 line 2 and continues without making changes..
â user203269
Dec 2 '16 at 12:32
Hi Stephane, This awk does the first three values correctly, then it deletes column1 line 2 and continues without making changes..
â user203269
Dec 2 '16 at 12:32
1
1
@user203269, convert your file from MS-DOS to Unix first.
â Stéphane Chazelas
Dec 2 '16 at 12:50
@user203269, convert your file from MS-DOS to Unix first.
â Stéphane Chazelas
Dec 2 '16 at 12:50
 |Â
show 1 more comment
up vote
3
down vote
Simply with GNU sed
, using -i
to replace text directly in the file:
sed -i 's:(.*s)(.*s)(.*):121:g' textfile
The columns are matched by regex groups in the parenthesis, reusing them with 1
and 2
and then using a "1" to replace the last group.
In this use case, the solution proposed using awk
is nice and short as well.
add a comment |Â
up vote
3
down vote
Simply with GNU sed
, using -i
to replace text directly in the file:
sed -i 's:(.*s)(.*s)(.*):121:g' textfile
The columns are matched by regex groups in the parenthesis, reusing them with 1
and 2
and then using a "1" to replace the last group.
In this use case, the solution proposed using awk
is nice and short as well.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Simply with GNU sed
, using -i
to replace text directly in the file:
sed -i 's:(.*s)(.*s)(.*):121:g' textfile
The columns are matched by regex groups in the parenthesis, reusing them with 1
and 2
and then using a "1" to replace the last group.
In this use case, the solution proposed using awk
is nice and short as well.
Simply with GNU sed
, using -i
to replace text directly in the file:
sed -i 's:(.*s)(.*s)(.*):121:g' textfile
The columns are matched by regex groups in the parenthesis, reusing them with 1
and 2
and then using a "1" to replace the last group.
In this use case, the solution proposed using awk
is nice and short as well.
edited Dec 2 '16 at 12:11
Stéphane Chazelas
284k53524862
284k53524862
answered Dec 1 '16 at 10:30
mazs
2,5151522
2,5151522
add a comment |Â
add a comment |Â
up vote
2
down vote
this will do the job:
cat textfiles | cut -d' ' -f-2 | sed 's/$/ 1/'
cat file.txt | cut -d' ' -f-2 | sed 's/$/ 1/' 646 6 0.5 1 prints out one line (the last line) in the terminal, but does not change the file.txt...
â user203269
Dec 2 '16 at 12:15
add a comment |Â
up vote
2
down vote
this will do the job:
cat textfiles | cut -d' ' -f-2 | sed 's/$/ 1/'
cat file.txt | cut -d' ' -f-2 | sed 's/$/ 1/' 646 6 0.5 1 prints out one line (the last line) in the terminal, but does not change the file.txt...
â user203269
Dec 2 '16 at 12:15
add a comment |Â
up vote
2
down vote
up vote
2
down vote
this will do the job:
cat textfiles | cut -d' ' -f-2 | sed 's/$/ 1/'
this will do the job:
cat textfiles | cut -d' ' -f-2 | sed 's/$/ 1/'
answered Dec 1 '16 at 9:30
Wissam Roujoulah
2,833316
2,833316
cat file.txt | cut -d' ' -f-2 | sed 's/$/ 1/' 646 6 0.5 1 prints out one line (the last line) in the terminal, but does not change the file.txt...
â user203269
Dec 2 '16 at 12:15
add a comment |Â
cat file.txt | cut -d' ' -f-2 | sed 's/$/ 1/' 646 6 0.5 1 prints out one line (the last line) in the terminal, but does not change the file.txt...
â user203269
Dec 2 '16 at 12:15
cat file.txt | cut -d' ' -f-2 | sed 's/$/ 1/' 646 6 0.5 1 prints out one line (the last line) in the terminal, but does not change the file.txt...
â user203269
Dec 2 '16 at 12:15
cat file.txt | cut -d' ' -f-2 | sed 's/$/ 1/' 646 6 0.5 1 prints out one line (the last line) in the terminal, but does not change the file.txt...
â user203269
Dec 2 '16 at 12:15
add a comment |Â
up vote
-1
down vote
cat filename | awk -F ' ' '$3=1; print $0' > filename
Could you please edit your post to include more context as to why you feel this is the solution?
â kemotep
Apr 11 at 22:15
add a comment |Â
up vote
-1
down vote
cat filename | awk -F ' ' '$3=1; print $0' > filename
Could you please edit your post to include more context as to why you feel this is the solution?
â kemotep
Apr 11 at 22:15
add a comment |Â
up vote
-1
down vote
up vote
-1
down vote
cat filename | awk -F ' ' '$3=1; print $0' > filename
cat filename | awk -F ' ' '$3=1; print $0' > filename
edited Apr 11 at 22:22
Jeff Schaller
32.4k849110
32.4k849110
answered Apr 11 at 21:11
Thriller
11
11
Could you please edit your post to include more context as to why you feel this is the solution?
â kemotep
Apr 11 at 22:15
add a comment |Â
Could you please edit your post to include more context as to why you feel this is the solution?
â kemotep
Apr 11 at 22:15
Could you please edit your post to include more context as to why you feel this is the solution?
â kemotep
Apr 11 at 22:15
Could you please edit your post to include more context as to why you feel this is the solution?
â kemotep
Apr 11 at 22:15
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f327280%2freplace-all-values-in-one-column-to-1%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password