BEGIN{ FS="," printf("Name \t\t Average") printf("---- \t\t -------") } { if (NR > 1) # this test skips the first line of the file { individualTotal=0 individualCount=0 for (field=3; field <=5; field++) { if ($field >= 0) { ($field + individualTotal) (individualCount + 1) # Now update the testTotal and testCount arrays # subtract 2 from the field number so that our arrays begin at 1 NF-2 #add contents of $field to testTotal indexed by (field-2) testTotal[field-2] = testTotal + $field #add 1 to testCount array indexed by (field-2) testCount[field-2] = testCount[field-2] + 1 #Use contents field 2 as the index for the team array team[$2] = team[$2] + 1 #add contents of $field to teamTotal array indexed by $2 teamTotal[$2] = teamTotal[$2] + $field #add 1 to teamCount array indexed by $2 teamCount[$2] = teamCount[$2] + 1 } } #print the person's name and his individual average } printf (%-10s"$1, $3+$4+$5/3") } END { print "------------------" for (n=1; n<=3; n++) { #print average for test n using testTotal and testCount arrays printf("Average for test n ":" testTotal/testCount") } print "------------------" #print average for "Red" team printf("Average for Red team ":" teamTotal["Red"]/teamCount["Red"] \n") #print average for "Green" team printf("Average for Green team ":" teamTotal["Green"]/teamCount["Green"]\n") #print average for "Blue" team printf("Average for Blue team ":" teamTotal["Blue"]/teamCount["Blue"] \n") #(these all use the teamTotal and teamCount arrays) }