2

Suppose I have many files in this directory. I want to replace "hello" with "goodbye" everywhere, also recursively

TIMEX
  • 238,746
  • 336
  • 750
  • 1,061
  • 1
    Do you care if substrings are also replaced? All current answers will replace words like "shellout" with "sgoodbyeut". I would think they should deal with token replacement only. – Alex M Feb 14 '11 at 19:46
  • Take a look at this: http://stackoverflow.com/questions/6758963/find-and-replace-with-sed-in-directory-and-sub-directories – rowana Apr 26 '16 at 10:37

3 Answers3

10

find . -type f -exec sed -i 's/hello/goodbye/g' {} +

Antti
  • 11,444
  • 2
  • 22
  • 29
1

for file in $(find ./) ; do sed -e 's/hello/goodbye/g' $file > tmp && mv tmp $file ; done

Fred
  • 4,803
  • 1
  • 28
  • 47
0

You can use a perl one-liner

perl -p -i -e 's/oldstring/newstring/g' `find ./ -name *.html`

(Taken from here http://joseph.randomnetworks.com/2005/08/18/perl-oneliner-recursive-search-and-replace/)

Thomas
  • 162,537
  • 44
  • 333
  • 446
DrNoone
  • 261
  • 1
  • 11