Created
June 6, 2012 19:45
-
-
Save carlosmcevilly/2884220 to your computer and use it in GitHub Desktop.
Do a simple rename of some strings in some files stored under 'Source/'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# requires ack: http://betterthangrep.com/ | |
# is there a better way to pass in the arguments to this perl one-liner other than using the environment? pretty hacky. could just rewrite the whole thing as a Perl script using File::Find | |
# todo: redo this to use find, xargs, and grep in case ack isn't available | |
# todo: this looks only for files in a "Source" directory; generalize it | |
export old=$1 | |
export new=$2 | |
if [ "$new" == '' ]; then | |
echo usage: $0 original-name new-name | |
exit -1 | |
fi | |
for n in `ack -u "\b$old\b" | grep ^Source | cut -f1 -d':'`; do | |
echo $n | |
perl -pi -e '$new=$ENV{"new"};$old=$ENV{"old"}; s/\b$old\b/$new/g;' $n | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment