Skip to content

Instantly share code, notes, and snippets.

@carlosmcevilly
Created June 6, 2012 19:45
Show Gist options
  • Save carlosmcevilly/2884220 to your computer and use it in GitHub Desktop.
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/'
#!/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