Using awk printf to urldecode text

后端 未结 5 1527
一向
一向 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条回答
  •  -上瘾入骨i
    2021-01-05 03:53

    This relies on gnu awk's extension of the split function, but this works:

    gawk '{ numElems = split($0, arr, /%../, seps);
            outStr = ""
            for (i = 1; i <= numElems - 1; i++) {
                outStr = outStr arr[i]
                outStr = outStr sprintf("%c", strtonum("0x" substr(seps[i],2)))
            }
            outStr = outStr arr[i]
            print outStr
          }'
    

提交回复
热议问题