uni

University stuff
git clone git://git.christosmarg.xyz/uni-assignments.git
Log | Files | Refs | README | LICENSE

ex3_courseavgs.awk (596B)


      1 #!/usr/bin/env -S awk -f
      2 
      3 BEGIN {
      4         # Quit if we don't have an input file.
      5         if (ARGC < 2) {
      6                 print "usage: ex3_courseavgs.awk gradefile";
      7                 exit 1;
      8         }
      9 }
     10 
     11 {
     12         # Loop from the 4th field onwards and
     13         # add its value to the sum array.
     14         for (i = 4; i <= NF; i++)
     15                 sum[i] += $i;
     16 }
     17 
     18 END {
     19         # `NR` is the number of rows in the file, so
     20         # we divide by that since each column is a
     21         # course.
     22         cnt = 1;
     23         for (i = 4; i <= NF; i++)
     24                 print "Course", cnt++":", sum[i] / NR;
     25 }