Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to globally replace strings in lines NOT starting with a certain pattern

Tags:

sed

People also ask

How do you replace some text pattern with another text pattern in a file?

`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.

Which command is used to replace a pattern in file with another?

Replacing or substituting string : Sed command is mostly used to replace the text in a file.

How do you replace all occurrences of a word in a file using a Linux command?

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