Skip to content

Instantly share code, notes, and snippets.

@openglfreak
Created January 31, 2019 11:58
Show Gist options
  • Save openglfreak/2ad95e9a8ecbcf1a166bcd6dd6e827ae to your computer and use it in GitHub Desktop.
Save openglfreak/2ad95e9a8ecbcf1a166bcd6dd6e827ae to your computer and use it in GitHub Desktop.
Escape a string for use as/in a sed replacement.
# Escapes a string for use as/in a sed replacement
# https://stackoverflow.com/a/2705678
sed_escape_replacement() {
sed -e 's/[\/&]/\\&/g' -e 's/$/\\n/g' | tr -d '\n' | head -c -2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment