Skip to content

Instantly share code, notes, and snippets.

@Chris2048
Last active October 7, 2015 11:57
Show Gist options
  • Save Chris2048/3160887 to your computer and use it in GitHub Desktop.
Save Chris2048/3160887 to your computer and use it in GitHub Desktop.
sed sanitise bash function
# Use this shell function to sanitise variables before using them with sed,
# or in another context where escapes might be substituted
funtion san {
echo "$1" | tr -d '\n' | xxd -plain | sed 's/\(..\)/\\x\1/g' | tr -d '\n'; }
# Use it like this
# somevar=$(san "$somevar")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment