Posted By

irishsk on 03/24/12


Tagged


Versions (?)

Nix search and replace


 / Published in: Bash
 

Nix search replace using sed

  1. !/bin/bash
  2.  
  3. FOLDER="/Users/path/to/test/original/"
  4. echo "******************************************"
  5. echo enter word to replace
  6. read searchterm
  7. echo enter word that replaces
  8. read replaceterm
  9.  
  10.  
  11.  
  12. for file in $(grep -l -R $searchterm $FOLDER)
  13.  
  14.  
  15. do
  16.  
  17. sed -e "s/$searchterm/$replaceterm/g" $file > /Users/path/to/test/tmp/tempfile.tmp
  18. mv /Users/path/to/test/tmp/tempfile.tmp $file
  19.  
  20. echo "Modified: " $file
  21.  
  22. done
  23.  
  24.  
  25.  
  26.  
  27. echo " *** All Done! *** "

Report this snippet  

You need to login to post a comment.