From: http://aaronw.me/static/779.html
This is the first method: (punctuation will be missed)
#! /Bin/Shawk 'in in {hextab = "0123456789abcdef" for (I = 1; I <= 255; ++ I) Ord [I] = sprintf ("% C ", i) ;}{ decoded = "" for (I = 1; I <= length ($0); ++ I) {c = substr ($0, I, 1) if (C ~ /[A-zA-Z0-9. -]/) {decoded = decoded C # Safe character} else if (C = "") {decoded = decoded "+" # Special Handling} else if (C = "%") {HI = substr ($0, I + ); low = substr ($0, I + 2, 1); I ++ decoded = decoded ord [(index (hextab, hi)-1) * 16 + index (hextab, low)-1] }}end {print decoded }'
This is the second method:
#/Bin/Shawk 'in in {for (I = 0; I <10; I ++) hex [I] = I; hex ["A"] = hex ["A"] = 10; hex ["B"] = hex ["B"] = 11; hex ["C"] = hex ["C"] = 12; hex ["D"] = hex ["D"] = 13; hex ["E"] = hex ["E"] = 14; hex ["F"] = hex ["F"] = 15 ;} {gsub (/\ +/, ""); I = $0; while (MATCH (I,/% .. /) {If (rstart> 1); printf "% s", substr (I, 1, RSTART-1); printf "% C", Hex [substr (I, rstart +)] * 16 + hex [substr (I, rstart +)]; I = substr (I, rstart + rlength);} print I ;}'