uni

University stuff
git clone git://git.margiolis.net/uni.git
Log | Files | Refs | README | LICENSE

ex6_votes.awk (575B)


      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: ex6_votes.awk votefile";
      7                 exit 1;
      8         }
      9 
     10         max = 0;
     11 }
     12 
     13 {
     14         cnt = 0;
     15         # We're testing only against 'y's,
     16         # no need to check for 'n's.
     17         for (i = 2; i <= NF; i++)
     18                 if ($i == "y")
     19                         cnt++;
     20         if (cnt > max) {
     21                 max = cnt;
     22                 winner = $1;
     23         }
     24 }
     25 
     26 END {
     27         print "Winner:", winner;
     28         print "Votes:", max;
     29 }