Skip to content

Instantly share code, notes, and snippets.

View eastside's full-sized avatar

Adam eastside

View GitHub Profile
@eastside
eastside / find-and-replace.sh
Created October 12, 2021 17:49
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"