Skip to content

Instantly share code, notes, and snippets.

@pfaffman pfaffman/fixnames
Last active Mar 31, 2016

Embed
What would you like to do?
#!/usr/bin/env bash
# fixnames
# Jay Pfaffman <jay@pfaffman.com>
# Available from https://gist.github.com/pfaffman/8644399
if [ $# -lt 1 ]
then
echo "Usage " $0 files
echo " Replaces names (or any words) in files passed on the command line."
echo " Edit below to change what names get replaced."
exit
fi
# According to: http://stackoverflow.com/questions/17382272/beginning-and-end-of-words-in-sed-and-grep
# on OS X you'll need to use [[:<:]] and [[:>:]] for word boundary.
# Using \b or \< just doesn't work.
# For each first and last name, duplicate the sed line below to replace in all
# of the documents passed on the command line.
# Sites like http://listofrandomnames.com/ will give you lists of names.
for file in $*
do
echo -n "Processing " $file ". . . "
# Stick in as many names like these as you need to
# Whatever is in the first field between the /'s will be replaced by the second field.
sed --in-place -e 's/\<OLDNAME\>/NEWNAME/g' $file
echo done.
done
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.