Nix search and replace


/ Published in: Bash
Save to your folder(s)

Nix search replace using sed


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.