in reply to awk...ward

Though I generally much prefer Perl to awk, in this case I prefer your awk one-liner above to the equivalent Perl one-liner -- if calling from a /bin/sh script. My main suggestion is to write the whole script, not in /bin/sh, but Perl; then you don't need all these little one-liners. The only time I write /bin/sh over Perl is for truly tiny scripts or when I need the script to run on a machine that does not have Perl installed.