Skip to content

Instantly share code, notes, and snippets.

@nateflink
Last active December 18, 2015 13:49
Show Gist options
  • Save nateflink/5793139 to your computer and use it in GitHub Desktop.
Save nateflink/5793139 to your computer and use it in GitHub Desktop.
#!/bin/bash
#By Nate Flink
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
echo "Usage: ./$0 [path to files] [find string] [replace string]"
exit 1
fi
DIRPATH=$1
FIND=$2
REPLACE=$3
if [ ! -d "${DIRPATH}" ];
then
echo "Error: ${DIRPATH} doesn't exist"
exit 2
fi
#sed -i "" is needed by the osx version of sed (instead of sed -i)
find ${DIRPATH} -type f | xargs sed -i "" "s|${FIND}|${REPLACE}|g"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment