Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ## This script was created with the express purpose of easing the transition
- ## between quarters. invoking it as follows ./rename.sh $sdi <oldqtr> <currentqtr>
- ## gu13 (10au)
- if [ $# -lt 3 ] ; then
- echo -e "Syntax: rename <path> <find> <replace>"
- exit 1
- fi
- for file in `find ${1} -exec grep -l "${2}" {} \;` ; do
- echo $file
- read -p "Replace contents [Y/n]? " prompt
- if [[ -z "$prompt" || "$prompt" == "y" || "$prompt" == "Y" ]] ; then
- grep "${2}" $file
- read -p "Skip file? [y/N]" prompt
- if [ -n "$prompt" ] ; then
- if [[ "$prompt" == "y" || "$prompt" == "Y" ]] ; then
- continue
- fi
- fi
- read -p "Create backup [y/N]? " prompt
- if [ -n "$prompt" ] ; then
- if [[ "$prompt" == "y" || "$prompt" == "Y" ]] ; then
- cp $file "${file}.backup"
- fi
- fi
- touch "${file}.sedtemp"
- sed "s/${2}/${3}/g" "${file}" > "${file}.sedtemp"
- mv ${file}.sedtemp ${file}
- fi
- done
Add Comment
Please, Sign In to add comment