Skip to content

Instantly share code, notes, and snippets.

@sandcastle
Created August 3, 2018 14:07
Show Gist options
  • Save sandcastle/e830e1dcd4488db323785ff419660e1b to your computer and use it in GitHub Desktop.
Save sandcastle/e830e1dcd4488db323785ff419660e1b to your computer and use it in GitHub Desktop.
Replace text function for shell
function text_replace() {
case "${OSTYPE}" in
darwin*) PLATFORM="OSX" ;;
linux*) PLATFORM="LINUX" ;;
bsd*) PLATFORM="BSD" ;;
*) PLATFORM="UNKNOWN" ;;
esac
if [[ "${PLATFORM}" == "OSX" || "${PLATFORM}" == "BSD" ]]; then
find $1 -type f -name $2 -exec sed -i "" "s/$3/$4/g" {} +
else
find $1 -type f -name $2 -exec sed -i "s/$3/$4/g" {} +
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment