Advertisement
falconflame

supersed.sh

Mar 4th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.46 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #We can search and replace specific word in many files on the same directory at the same time
  4. #without the need of repeating the task
  5. #Made in three options, choose one depend on your condition
  6. #Whichever you choose, don't forget to add # in front of other command method
  7. #Tested and created by falconflame a.k.a dr. F
  8.  
  9. #The path after command "find" can be replace to any specific absolute or relative path
  10. #You can change .txt to other extension i.e. .doc .rtf .odt .php .html .xls .ppt et cetera
  11. #Input the specific word you'd like to change in findstring and replacestring
  12. find . *.txt -type f -exec sed -i 's/findstring/replacestring/g' {} \; #Dot (.) after find means current path
  13. echo "The word is successfully replaced!!!"
  14.  
  15. exit 0
  16.  
  17. #In case you already know the path, you can choose this option below and run it on the specific folder
  18. #If you prefer so, don't forget to add # comment to the command before and after this one
  19. for falcon in *.txt
  20.    do mv $falcon $falcon.tmp
  21.    sed -e 's/findstring/replacestring/g' $falcon.tmp > $falcon
  22.    rm -f $falcon.tmp
  23.    echo "The word is successfully replaced!!!"
  24. done
  25.  
  26. exit 0
  27.  
  28. #Or you could try this third method below
  29. find . *.txt -type f | xargs sed -i 's/findstring/replacestring/g'
  30. echo "The word is successfully replaced!!!"
  31.  
  32. exit 0
  33.  
  34. #Any ideas or comments? Contact me at: flame.axoneme@gmail.com or flame_axoneme@yahoo.fr
  35. #Or you can see me here: http://fajarichwannoor.wordpress.com
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement