Suppose I have many files in this directory. I want to replace "hello" with "goodbye" everywhere, also recursively
            Asked
            
        
        
            Active
            
        
            Viewed 3,940 times
        
    2
            
            
        - 
                    1Do 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 Answers
10
            find . -type f -exec sed -i 's/hello/goodbye/g' {} +
 
    
    
        Antti
        
- 11,944
- 2
- 24
- 29
- 
                    You may want to check that pattern. You may end up with instances of sgoodbyeil! – johnsyweb Feb 14 '11 at 21:08
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/)
- 
                    I took the liberty to fix the formatting... essential backticks were getting lost. – Thomas Feb 14 '11 at 19:47
 
     
    