I\'m using awk
to urldecode some text.
If I code the string into the printf
statement like printf \"%s\", \"\\x3D\"
it correct
To start with, I'm aware this is an old question, but none of the answers worked for me (restricted to busybox awk)
Two options. To parse stdin:
awk '{for (y=0;y<127;y++) if (y!=37) gsub(sprintf("%%%02x|%%%02X",y,y), y==38 ? "\\&" : sprintf("%c", y));gsub(/%25/, "%");print}'
To take a command line parameter:
awk 'BEGIN {for (y=0;y<127;y++) if (y!=37) gsub(sprintf("%%%02x|%%%02X",y,y), y==38 ? "\\&" : sprintf("%c", y), ARGV[1]);gsub(/%25/, "%", ARGV[1]);print ARGV[1]}' parameter
Have to do %25 last because otherwise strings like %253D get double-parsed, which shouldn't happen.
The inline check for y==38 is because gsub treats & as a special character unless you backslash it.