0

suppose I want to replace abc with xyz in all files in a directory. How do I write a script for this ?

Alex Jones
  • 6,353

1 Answers1

3

find . -type f | xargs sed -i 's/abc/xyz/g'

Use -maxdepth option if you don't want the action to take place recursively in your current working directory.

Sreeraj
  • 5,062
  • find . -maxdepth 1 -type f | xargs sed -i 's/abc/xyz/g' - this is non-recursive, ie., it will replace abc in the files that reside only in your current working directory. – Sreeraj Nov 26 '14 at 06:42
  • 2
    you should use find ... -exec sed '...' {} + – mikeserv Nov 26 '14 at 07:21