Skip to content

Instantly share code, notes, and snippets.

@orita
Created March 24, 2014 09:00
Show Gist options
  • Save orita/9736692 to your computer and use it in GitHub Desktop.
Save orita/9736692 to your computer and use it in GitHub Desktop.
URL encode opensocial_owner_id
BEGIN {
for (i = 0; i <= 255; i++)
ord[sprintf("%c", i)] = i
}
# Encode string with application/x-www-form-urlencoded escapes.
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]/)
#if (c ~ /[-._*0-9A-Za-z]/)
res = res c
#else if (c == " ")
# res = res "+"
else
res = res "%" sprintf("%02X", ord[c])
}
return res
}
# Escape every line of input.
{
userid=gensub(/.*opensocial_owner_id=([a-zA-Z0-9%-]+).*/,"\\1",1,$0)
#print "###userid###"userid
sub(/opensocial_owner_id=[a-zA-Z0-9%-]+/,"opensocial_owner_id="escape(userid),$0)
print $0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment