Skip to content

Instantly share code, notes, and snippets.

@pfaffman
Last active March 31, 2016 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfaffman/8644399 to your computer and use it in GitHub Desktop.
Save pfaffman/8644399 to your computer and use it in GitHub Desktop.
#!/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