Conclusion

So this is how we can find and replace with sed in Directory and Sub Directories in Linux. In the above methodology, we used the sed command along with grep, xargs, and pipe delimiter ( | ).  


Find and Replace with sed in Directory and Sub Directories in Linux

sed stands for stream editor. It is a basic utility command in Linux that has basic functionality like inserting, deleting, finding, replacing, and searching text strings in a file. But sed is most commonly used for its substitution function i.e find and replace.

Syntax

sed OPTIONS... [script] [input_file]

e.g. 

sed "s/abc/ABC/g" abc.txt

Consider the above example, 

  1. “s/abc/ABC/g” – It is the [script] which specifies what actions are to be performed. 
  • ‘s/..’ ->>  tells that it is the substitution operation.
  • s/abc/..’ ->> “abc” will be the word after the substitution operation.
  • ‘s/abc/ABC/..’ ->> “ABC” is the string to be substituted with “abc”.
  • s/abc/ABC/g’ ->>  “g” means global. It specifies that all the matching occurrences should be substituted on the given line rather than the first occurrence only.

      2. abc.txt –  It is the [input_file], where the name of the file which is needed to be searched is specified.

Output

 

Similar Reads

Find and Replace with sed in Directory and Sub Directories in Linux

Scenario...

Conclusion :

So this is how we can find and replace with sed in Directory and Sub Directories in Linux. In the above methodology, we used the sed command along with grep, xargs, and pipe delimiter ( | )....