Using awk printf to urldecode text

后端 未结 5 1531
一向
一向 2021-01-05 03:23

I\'m using awk to urldecode some text.

If I code the string into the printf statement like printf \"%s\", \"\\x3D\" it correct

5条回答
  •  臣服心动
    2021-01-05 04:05

    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}'
    

提交回复
热议问题