awkprintfurldecodebusybox

Using awk printf to urldecode text


I'm using awk to urldecode some text.

If I code the string into the printf statement like printf "%s", "\x3D" it correctly outputs =. The same if I have the whole escaped string as a variable.

However, if I only have the 3D, how can I append the \x so printf will print the = and not \x3D?

I'm using busybox awk 1.4.2 and the ash shell.


Solution

  • Since you're using ash and Perl isn't available, I'm assuming that you may not have gawk.

    For me, using gawk or busybox awk, your second example works the same as the first (I get "=" from both) unless I use the --posix option (in which case I get "x3D" for both).

    If I use --non-decimal-data or --traditional with gawk I get "=".

    What version of AWK are you using (awk, nawk, gawk, busybox - and version number)?

    Edit:

    You can coerce the variable's string value into a numeric one by adding zero:

    ~/busybox/awk 'BEGIN { string="3D"; pre="0x"; hex=pre string; printf "%c", hex+0}'