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

1

1 Answer 1

9

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.