Reputation: 464
I am using GNU sed command (GNU sed version 4.2.1) for search and replace in file. I want the input file to remain intact hence I am using sed's file writing option.
Following is the command
sed -e "s/INSERT/UPDATE/w output.txt" "input.txt"
But problem with above command is, it does not write the unmatched lines. i.e. the lines in which the text to be searched if not found then that line is not getting written in output.txt file.
I want unmatched lines to be written in output.txt
how this can be achieved?
Upvotes: 0
Views: 490
Reputation: 241988
Use w
as a separate command, i.e.:
sed -e 's/INSERT/UPDATE/' -e 'w output.txt' input.txt
or, if your sed
supports it, you can use a semicolon:
sed -e 's/INSERT/UPDATE/;w output.txt' input.txt
But, if you really just want the output in a file, use redirection:
sed -e 's/INSERT/UPDATE/' input.txt > output.txt
Upvotes: 1