1

There are some 10 files say file a, file b, file c,...file j. I have to search all these files and replace the string "xyz" with "abc". Most important this has to be done with a shell script using for loop and sed command.can somebody provide the solution here

anonymous
  • 21
  • 1
  • 1
  • 3
  • possible duplicate of [Awk/Sed: How to do a recursive find/replace of a string?](http://stackoverflow.com/questions/1583219/awk-sed-how-to-do-a-recursive-find-replace-of-a-string) – tripleee Apr 21 '15 at 11:44

1 Answers1

8

Use sed

sed -i s/xyz/abc/g files
  • -i will edit the files in place
  • s/// will specify the substitution (read the manual for the details)
  • g will replace more than one occurrence per line

for example

sed -i s/xyz/abc/g a b c d e f g h i j

or for all the files in the directory

sed -i s/xyz/abc/g *

Why a loop?

Matteo
  • 14,696
  • 9
  • 68
  • 106