Logan L.

asked • 08/24/22

Help with Unix Lab - AWK

Write a script called labscript3.awk that will print out all orders shipped in 2014. Print out region, item type and total profit. At the end, it should print out the average total profit (for these orders only). (5 points) 


Tried:

BEGIN {

printf "%-25s %-16s %-10s\n","region","item type","total profit" 

print "============================================================="

cnt=0 

sum=0.0 

}

{

if($1==2014){

printf "%-25s %-16s %.2f\n",$2,$3,$4

++cnt

sum += $4

}

}

END {

print "============================================================="

printf "The average total profit is : %.2f\n", sum/cnt

}


but it does not print the correct thing.


1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.