Skip to content

Instantly share code, notes, and snippets.

@cesarferreira
Forked from nateflink/findreplaceosx.sh
Created September 21, 2022 12:33
Show Gist options
  • Save cesarferreira/a4eef646208bc50a6917b6cd2a1e5139 to your computer and use it in GitHub Desktop.
Save cesarferreira/a4eef646208bc50a6917b6cd2a1e5139 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