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?
Use
was a separate command, i.e.:or, if your
sedsupports it, you can use a semicolon:But, if you really just want the output in a file, use redirection: