Find and Replace Text Across Multiple Files


Here is some ways to find and replace text in multiple files using sed or perl.

 

  • perl -pi -w -e 's/SEARCH/REPLACE/g;' *.txt
  • perl -e "s/SEARCH/REPLACE/g;" -pi.save $(find DirectoryName -type f)

    • It backs up the old file with a .save extension
  • find /home/user -type f -exec sed -i 's/SEARCH/REPLACE/g' {} \;

In Mac you have add "-e" with sed and the command becomes

  • find /home/user -type f -exec sed -i -e 's/SEARCH/REPLACE/g' {} \;