ex2_studavgs.awk (439B)
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: ex2_studavgs.awk gradefile"; 7 exit 1; 8 } 9 } 10 11 { 12 sum = cnt = 0; 13 for (i = 4; i <= NF; i++) { 14 sum += $i; 15 cnt++; 16 } 17 18 # We're calling sort(1) from awk(1). 19 print "Student", NR",", $1, $2",", sum / cnt | "sort -Vrk5"; 20 }