Guest User

Untitled

a guest
Jun 25th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #!/bin/bash
  2. ## This script was created with the express purpose of easing the transition
  3. ## between quarters. invoking it as follows ./rename.sh $sdi <oldqtr> <currentqtr>
  4. ## gu13 (10au)
  5. if [ $# -lt 3 ] ; then
  6. echo -e "Syntax: rename <path> <find> <replace>"
  7. exit 1
  8. fi
  9.  
  10. for file in `find ${1} -exec grep -l "${2}" {} \;` ; do
  11. echo $file
  12. read -p "Replace contents [Y/n]? " prompt
  13. if [[ -z "$prompt" || "$prompt" == "y" || "$prompt" == "Y" ]] ; then
  14. grep "${2}" $file
  15. read -p "Skip file? [y/N]" prompt
  16. if [ -n "$prompt" ] ; then
  17. if [[ "$prompt" == "y" || "$prompt" == "Y" ]] ; then
  18. continue
  19. fi
  20. fi
  21. read -p "Create backup [y/N]? " prompt
  22. if [ -n "$prompt" ] ; then
  23. if [[ "$prompt" == "y" || "$prompt" == "Y" ]] ; then
  24. cp $file "${file}.backup"
  25. fi
  26. fi
  27. touch "${file}.sedtemp"
  28. sed "s/${2}/${3}/g" "${file}" > "${file}.sedtemp"
  29. mv ${file}.sedtemp ${file}
  30.  
  31. fi
  32. done
Add Comment
Please, Sign In to add comment