2

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

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
  • 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,944
  • 2
  • 24
  • 29
1

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

Fred
  • 4,894
  • 1
  • 31
  • 48
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
  • 174,939
  • 50
  • 355
  • 478
DrNoone
  • 261
  • 1
  • 11