Skip to content

Instantly share code, notes, and snippets.

@moyashi
Created November 13, 2012 04:13
Show Gist options
  • Save moyashi/4063894 to your computer and use it in GitHub Desktop.
Save moyashi/4063894 to your computer and use it in GitHub Desktop.
#!/usr/bin/awk
BEGIN {
for (i = 0; i <= 255; i++) {
ord[sprintf("%c", i)] = i
}
}
function escape(str, c, len, res) {
len = length(str)
res = ""
for (i = 1; i <= len; i++) {
c = substr(str, i, 1);
if (c ~ /[0-9A-Za-z]/)
res = res c
else
res = res "%" sprintf("%02X", ord[c])
}
return res
}
{ print escape($0) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment