`sed` command is one of the ways to do replacement task. This command can be used to replace text in a string or a file by using a different pattern.
Replacing or substituting string : Sed command is mostly used to replace the text in a file.
Find and replace text within a file using sed command Use Stream EDitor (sed) as follows: sed -i 's/old-text/new-text/g' input.txt. The s is the substitute command of sed for find and replace. It tells sed to find all occurrences of 'old-text' and replace with 'new-text' in a file named input.txt.
You just need to negate the match using !
:
sed -i '/^##Input/! s/foo/bar/g' myfile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With