1

I am trying to replace on any file in a directory a specific word but this doesn't work

find . -type f -print0 | xargs -0 sed -i 's/oldWord/NewWord/g'

Subsequently I would also like to change the names of few files, but still this doesn't work

find . -exec rename 's/oldFileName/NewFileName/' {} ";"

I am using OSX terminal, any idea why?

Sundeep
  • 23,246
  • 2
  • 28
  • 103
Pasquale Sada
  • 327
  • 2
  • 4
  • 12
  • 1
    as per https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux you would need `-i ''` on osx... and you don't need xargs... try `find . -type f -exec sed -i '' 's/oldWord/NewWord/g' {} \;` – Sundeep Jul 14 '17 at 11:52
  • for the first line I get "sed: RE error: illegal byte sequence" and for rename I get -bash: rename: command not found – Pasquale Sada Jul 14 '17 at 15:15
  • Rename now works! I just did brew install rename. – Pasquale Sada Jul 14 '17 at 15:24
  • 1
    Ok run export LC_CTYPE=C and then export LANG=C before running the sed command. Problem fixed! – Pasquale Sada Jul 14 '17 at 15:47
  • I think you can also do `LC_ALL=C ` on single command line instead of exporting... – Sundeep Jul 14 '17 at 16:07

0 Answers0