Justice London is my hero.
#!/bin/bash

#Below script is to, per request, look for a specific string in a group of files
#As well, it will replace that string with another given.
#Tried to account for as many ‘bonehead’ entries as I could.
#Scripting questions: jlondon@syrussystems.com

#From user input, takes the given strings and replaces if found in a file
#Uses sed for editing
string_rep() {
run_folder=”$1″
in_string=$2
out_string=$3

#Searches for files with the string in them, will pass to sed and edit
#one-by-one. This might not work for folders with spaces….
for file in `grep -r “$in_string” “$run_folder”| cut -f1 -d “:”`; do
#sed -i “s/$in_string/$out_string/g” $file
echo “$file”
done

unset run_folder
unset in_string
unset out_string
}

#Grabs the users input to script and gives help, or errors out if incorrect
#input is detected
get-input() {
param=”$1″
folder=”$2″
oldstring=”$3″
newstring=”$4″

case “$param” in
‘-h’ | ‘–help’)
echo “The purpose of this script is to find a group of files”
echo “In a named directory and replace a string in those files”
echo “Form: string-replace
echo “Example: string-replace –edit /my/folder \”Joe Someone\” \”Joe Noname\”"
;;
‘-e’ | ‘–edit’)
if [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]; then
echo “Invalid arguments. Please see –help!”
exit 1
fi
if [ ! -e "$folder" ]; then
echo “Specified folder was not found, quitting!!”
exit 1
else
string_rep “$folder” “$oldstring” “$newstring”
fi

;;
‘-42′)
echo “Very funny, Douglas.”
;;
* )
echo “Invalid or null input. Run -h or –help for information”
;;
esac

unset param
unset folder
unset oldstring
unset newstring
}

#Beginning task of the script. Makes calls to input function and returns
#With status from there
func_main() {
#Simple array to clean up user input
input=( “$1″ “$2″ “$3″ “$4″ )

get-input “${input[0]}” “${input[1]}” “${input[2]}” “${input[3]}”

#Everything ran ‘okay’. Cleanup (just in case) and exit the script
unset input
exit 0
}

#Start main task
func_main “$1″ “$2″ “$3″ “$4″

echo “If you got here, please make sure that you have a current bash interpreter”
exit 9