Linux find certain files containing text and replace that text

Here we go!  This was a fun command to type out.


  • Find files in the current and sub-directories matching the name *Spec*
  • Files must contain the "search_text"
  • Replace search_text with repalce_text


find . -name "*Spec*" -exec grep -l "search_text" {} \; | xargs perl -pi -e "s/search_text/replace_text/"

Danger! Be careful with this command.  Don't blame me if you mess up all your files!

Comments

Popular Posts