嗨,我想列出报告的总数。试图列出总数。但不确定使用什么代码将awk中的total salaried
and组合在一起total hourly
请指教
结果:
Salaried:
Frank $2333
Mary $1111
Total salaried: $3444
Hourly:
Chris $122
Total Hourly:122
----------------------
Grand Total: $3566
.txt 文件:
顺序如下:[id]、[name]、[title]、[phone]、[type]、[pay]
3,Frank,CFO,91111453,Salaried,2333
1,Mary,CEO,93424222,Salaried,1111
5,John,Sales user,9321312,Commission,9999
7,Chris,Admin,98888753,Hourly,122
代码 :
#salaried
awk -F, 'BEGIN {print "Salaried"} $5=="Salaried"{salaried+=$6; printf "%s\t\t\t\t$%s\n", $2, $6} END {printf "Total salaried payroll: \t$%s", salaried}' $PAYROLL
echo
echo
#hourly
awk -F, 'BEGIN {print "Hourly"} $5=="Hourly"{hourly+=$6; printf "%s\t\t\t\t$%s\n", $2, $6} END {printf "Total Hourly payroll: \t\t$%s", hourly}' $PAYROLL
echo
echo "Grand total: