0

This awk command works well for decoding all characters at once:

awk -niord '{printf RT?$0chr("0x"substr(RT,2)):$0}' RS=%..


But I need commands to decode and encode specific URL characters. For example I only need to decode %3d and %26 or vice versa encode = and & in a file.

https%3a%2f%2fgoogle.com%2fsearch%3fq%3dstackoverflow%26param%3dvalue

Desired output for decoding

https%3a%2f%2fgoogle.com%2fsearch%3fq=stackoverflow&param=value

Desired output for encoding

https://google.com/search?q%3dstackoverflow%26param%3dvalue


UPDATE

Although it is possible to use sed 's/%3d/\=/g' | sed 's/%26/\&/g' to replace a character, but I'm still looking for a way to decode or encode some specific characters at once, (put them in one sed or awk or whatever instead of using two sed command). Tools other than sed are welcome.

I need to replace %3d with = and replace %26 with & and vice versa.

Thanks

sof31
  • 87
  • 5

0 Answers0