Skip to content

Instantly share code, notes, and snippets.

@janroz
Forked from nateflink/findreplaceosx.sh
Created October 20, 2019 18:21
Show Gist options
  • Save janroz/65cec5dd10239beab62b734b588e89a7 to your computer and use it in GitHub Desktop.
Save janroz/65cec5dd10239beab62b734b588e89a7 to your computer and use it in GitHub Desktop.
#!/bin/bash
#By Nate Flink
#Invoke on the terminal like this
#curl -s https://gist.github.com/nateflink/9056302/raw/findreplaceosx.sh | bash -s "find-a-url.com" "replace-a-url.com"
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: ./$0 [find string] [replace string]"
exit 1
fi
FIND=$1
REPLACE=$2
#needed for byte sequence error in ascii to utf conversion on OSX
export LC_CTYPE=C;
export LANG=C;
#sed -i "" is needed by the osx version of sed (instead of sed -i)
find . -type f -exec 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