Article 51K6Z Please help me understand this.

Please help me understand this.

by
jessmister04
from LinuxQuestions.org on (#51K6Z)
Hello, I am in my second UNIX class and am having a little bit of problems. This is our first week covering awk commands. We are using a csv file called chores.csv. We also are writing the awk commands in a separate file. Below is my code for average.awk. My goal is to turn average.awk into a file that will take in chores.csv information and output the average length of time the chores would take to complete. My code works good except the average is wrong because the header is included in N. The correct output should read 32.14. Thank you for any tips or help.

average.awk #code executed before input fields

BEGIN{
FS="," #field separator set to comma
}
{
if(NR!=1) #if Number of Rows is not = 1

sum += 3 #sum will add and assign to itself field $3

}
END{
avg=sum/NR #Here is my problem I think NR is adding
# the header right??

printf("Average: %.2f\n", avg) #print Average floating-point num
#with two decimal places.

Here is the chores.csv

Chore Name,Assigned to,estimate,done?
Laundry,Chelsey,45,N
Wash Windows,Sam,60,Y
Mop kitchen,Sam,20,N
Clean cookware,Chelsey,30,N
Unload dishwasher,Chelsey,10,N
Dust living room,Chelsey,20,N
Wash the dog,Sam,40,Nlatest?d=yIl2AUoC8zA latest?i=z9MPX8yjOB8:YY7dNabdQvs:F7zBnMy latest?i=z9MPX8yjOB8:YY7dNabdQvs:V_sGLiP latest?d=qj6IDK7rITs latest?i=z9MPX8yjOB8:YY7dNabdQvs:gIN9vFwz9MPX8yjOB8
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments