Good afternoon all,
I want to ask how to change some letter in my file with other letter in spesific line
eg.
data.txt
1
1
1
0
0
0
0
for example i want to change the 4th line with character 1.
How could I do it by SED or AWK.
I have tried to run this code but actually did not modify the data.txt file and just print the result to screen.
sed -e "4s/0/1/" data.txt
RudiC
May 13, 2015, 4:51am
2
That's how it works. Redirect the output to a temp file and then, mv
the temp file to data.txt, overwriting it.
Or, use ed
instead of sed
:
ed data.txt <<-EOF
4s/0/1/
w
q
EOF
or:
printf '%s\n' '4s/0/1' w q | ed data.txt
With GNU sed and BSD sed, there is the -i
option for in-place editing, but there the recommend option is to have it automatically create a backup file as well..