This is with gawk 4.0.0, running on Windows 7 with cygwin. The program is invoked like
gawk -f procjournal.gawk testdata
I have some data that looks like this:
"Date";"Type";"Amount";"Balance"
"6/11/2013 11:51:17 AM";"Transaction Tax";-427.5;399313884.46
"6/11/2013 11:51:17 AM";"Market Transaction";47500;399314311.96
"6/11/2013 11:12:42 AM";"Transaction Tax";-549.92;399266811.96
"6/11/2013 11:12:42 AM";"Market Transaction";61101.78;399267361.88
I want to extract the lines for transactions, strip the date part from the 1st field, and reformat the time stamp as a decimal. I thought I could do it with this awk program:
FS=";"
OFS=";"
/Market Transaction/ {
split($1, itemdate, " ");
tmp = itemdate[2];
split(tmp, hms, ":");
timestamp = hms[3] + (hms[2] * 60) + (hms[1] * 3600);
if (itemdate[3] == "AM")
timestamp += 12 * 3600;
timestamp /= 3600.0;
$1 = timestamp;
print;
}
but my output looks like this:
"Date";"Type";"Amount";"Balance"
"Date";"Type";"Amount";"Balance"
"6/11/2013 11:51:17 AM";"Transaction Tax";-427.5;399313884.46
"6/11/2013 11:51:17 AM";"Transaction Tax";-427.5;399313884.46
"6/11/2013 11:51:17 AM";"Market Transaction";47500;399314311.96
"6/11/2013 11:51:17 AM";"Market Transaction";47500;399314311.96
11.8547;"Market Transaction";47500;399314311.96
"6/11/2013 11:12:42 AM";"Transaction Tax";-549.92;399266811.96
"6/11/2013 11:12:42 AM";"Transaction Tax";-549.92;399266811.96
"6/11/2013 11:12:42 AM";"Market Transaction";61101.78;399267361.88
"6/11/2013 11:12:42 AM";"Market Transaction";61101.78;399267361.88
11.2117;"Market Transaction";61101.78;399267361.88
Why are non-matching lines being printed, and how do I suppress that?