Skip to content

Instantly share code, notes, and snippets.

@eastside
Created October 12, 2021 17:49
Show Gist options
  • Save eastside/aa4ed0a774a3693b8559eee19f884f95 to your computer and use it in GitHub Desktop.
Save eastside/aa4ed0a774a3693b8559eee19f884f95 to your computer and use it in GitHub Desktop.
Find and replace bash script
# Put the thing you need to find here, like this gnarly SQL.
# It has a bunch of annoying characters that sed doesn't like,
# so we have to escape them.
KEYWORD="SET @@GLOBAL.GTID_PURGED=/*!80000 '+'*/ '';";
# Escape the gnarly stuff
ESCAPED_KEYWORD=$(printf '%s\n' "$KEYWORD" | sed -e 's/[]\/$*.^[]/\\&/g');
# Now we can find and replace the now-escaped text
sed "s/$ESCAPED_KEYWORD/$ESCAPED_REPLACE/g"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment