You need to adapt it depending on the file format, but the basic principle is here (tested with GNU Awk 3.1.7):
sh$ echo 'Hello%2C%20world%20%21' | awk ' { for (i = 0x20; i < 0x40; ++i) { repl = sprintf("%c", i); if ((repl == "&") || (repl == "\\")) repl = "\\" repl; gsub(sprintf("%%%02X", i), repl); gsub(sprintf("%%%02x", i), repl); } print } ' Hello, world !
If you have gawk , you can wrap this in a function (credit brendanh in the comment below ):
function urlDecode(url) { for (i = 0x20; i < 0x40; ++i) { repl = sprintf("%c", i); if ((repl == "&") || (repl == "\\")) { repl = "\\" repl; } url = gensub(sprintf("%%%02X", i), repl, "g", url); url = gensub(sprintf("%%%02x", i), repl, "g", url); } return url; }
source share