I am enclosing script, input file and output of a file...problem is that the END action of the script won't execute for $5...It gives me a value of 0. If I use $3 or $4 in line 7 of the script, it works fine. Can anyone explain why it's not recognizing $5? Also, there is an annoying '0' this is appearing in line 2 of $6 that I can't get rid of and can't find the source (this is only a 5 column file)...any ideas?
Thanks! (PS - I know it looks ugly... apparently formatting doesn't appear to carry over as written).
command: awk -f report.awk filename
Input file:
Code:
First Name Last Name Rate Hours Total Pay
George White 18.00 23
Mark Red 18.10 20
Mary Blue 10.89 25
Dan Black 12.00 0
Susan Green 18.00 40
Nora Brown 17.20 46
Bruce Purple 12.20 52
John Gray 11.00 39
Bob Gold 15.00 45
Steve Silver 14.67 25
Script:
Code:
BEGIN {print " Weekly Report"}
{OFS = "\t"}
{actual = $3 * $4}
{base = $3 * 40}
{ovt = ($4 - 40) * 1.5 * $3}
{total = 0}
{totPay += $5}
{
if ($4 > "40")
print $0, base + ovt
else
print $0, actual
}
END {print "Total Payroll",":", totPay}
Output:
Code:
Weekly Report
First Name Last Name Rate Hours Total Pay 0
George White 18.00 23 414
Mark Red 18.10 20 362
Mary Blue 10.89 25 272.25
Dan Black 12.00 0 0
Susan Green 18.00 40 720
Nora Brown 17.20 46 842.8
Bruce Purple 12.20 52 707.6
John Gray 11.00 39 429
Bob Gold 15.00 45 712.5
Steve Silver 14.67 25 366.75
Total Payroll : 0