Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Replace Or Fail
#!/usr/bin/env bash
replace_or_fail() {
FROM_VALUE=$1
TO_VALUE=$2
FILENAME=$3
echo "Replace from '$FROM_VALUE' to '$TO_VALUE' in '$FILENAME'... "
grep -q ${FROM_VALUE} ${FILENAME} && sed -i.old 's/'${FROM_VALUE}'/'${TO_VALUE}'/' ${FILENAME} || ( (>&2 echo "\033[0;31mError: '$FROM_VALUE' not found") && exit 1 )
echo "Done. "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.