04-26-2008
3,653,
12
Join Date: Mar 2008
Last Activity: 28 March 2011, 6:41 AM EDT
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks Given: 0
Thanked 12 Times in 10 Posts
sub does a substitution (replacement); it's basically equivalent to the sed command we discussed earlier, except you can also name an awk variable you want to perform the change on (in my case that was $3; if you leave it out, it modifies $0, i.e. the whole input line). So sub("foo", "bar", $3) will replace foo in $3 with bar. (Just the first occurrence, if there are multiple.)
Replace ":0" with just ":" before replacing ":" with "h " to get rid of any leading zero on the minutes field. (If the substitution can't be performed, it does nothing, so it's harmless to attempt it even on lines which don't have a zero.)
Last edited by era; 04-26-2008 at 04:07 PM..
Reason: Note that failed substitution is harmless