-1

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

2

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.

| improve this answer | |
  • 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. – Citylight Nov 26 '14 at 6:42
  • 2
    you should use find ... -exec sed '...' {} + – mikeserv Nov 26 '14 at 7:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.