Long Live Open Source Software !!

Are you a programmer?if yes, sometimes you need to replace many same string in your application source code at once. I’ve met that situation before. I run linux in my laptop and need to change some text to fulfill client need.
Maybe you’ll tell me that i can use sed. Actually i can use sed to fulfill my need. But sed is limited to one file only. If i want to do search and replace in many files, i must make some shell script. Because i didn’t want to use my brain just to make those shell script, i remember that i can use ‘find’ utility in linux to replace string in many files at once.
I combined find and sed to do search and replace in many files. Below is the command i used.
find [dirname] -name [filename] -type f -exec sed -i 's/[old string]/[new string]/g' {} \;

  • dirname is directory where your files located.
  • filename is your files name.You can use regex here to select many files.

Posted by Wordmobi

Be Sociable, Share!

Maybe you like this post too :