stringbashsed

Replace a string with another string in all files below my current dir


How do I replace every occurrence of a string with another string below my current directory?

Example: I want to replace every occurrence of www.fubar.com with www.fubar.ftw.com in every file under my current directory.

From research so far I have come up with

sed -i 's/www.fubar.com/www.fubar.ftw.com/g' *.php

Solution

  • You're on the right track, use find to locate the files, then sed to edit them, for example:

    find . -name '*.php' -exec sed -i -e 's/www.fubar.com/www.fubar.ftw.com/g' {} \;
    

    Notes