#http://het.as.utexas.edu/HET/Projects/WindRose/selecttimes.awk
function month(text, mon) {
#
# Convert a month name to a month number
#
if (text ~ /Jan/ ) mon = 1
if (text ~ /Feb/ ) mon = 2
if (text ~ /Mar/ ) mon = 3
if (text ~ /Apr/ ) mon = 4
if (text ~ /May/ ) mon = 5
if (text ~ /Jun/ ) mon = 6
if (text ~ /Jul/ ) mon = 7
if (text ~ /Aug/ ) mon = 8
if (text ~ /Sep/ ) mon = 9
if (text ~ /Oct/ ) mon = 10
if (text ~ /Nov/ ) mon = 11
if (text ~ /Dec/ ) mon = 12
if (mon == 0) {
Error(sprintf("BAD month %s\n",text),3);
}
return mon;
}
time_zone_index refers to the location of date's output on the current line being processed by gawk.
function time_stamp(time_zone_index, n,t,u) {
#eg Fri May 1 09:32:22 BST 2015
#mktime uses YYYY MM DD HH MM SS [DST]"
n=split($(time_zone_index-1),t,":");
if(n!=3) Error(sprintf("Bad time `%s'",$(time_zone_index-1),2));
u = sprintf("%s ",$(time_zone_index+1)); #year
u = sprintf("%s%s ",u,month($(time_zone_index-3)));
u = sprintf("%s%s ",u,$(time_zone_index-2)); #day
u = sprintf("%s%s ",u,t[1]); #hour
u = sprintf("%s%s ",u,t[2]); #minutes
u = sprintf("%s%s ",u,t[3]); #seconds
u = sprintf("%s%s", u,$time_zone_index); #eg BST or GMT
return mktime(u);
}
gcat.bat $Revision: 1.6 $ Sun May 3 13:50:32 BST 2015 ........ gcat.bat sam done Sun May 3 14:05:09 BST 2015Gawk script fragments:
start = time_stamp(9);
end = time_stamp(8); print "elapsed seconds",end-start;Output:
elapsed seconds 877