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,223
  • 17
  • 51
  • 83

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
  • 4,984
  • 10
  • 38
  • 57
  • `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