uni

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

ex1_cmds (927B)


      1 #!/bin/sh
      2 
      3 test $# -ne 1 && echo "usage: ${0##*/} gradefile" 1>&2 && exit 1
      4 test ! -f "${1}" && echo "${0##*/}: ${1}: no such file" 1>&2 && exit 1
      5 
      6 file="${1}"
      7 
      8 echo "First names starting with K or N:"
      9 awk '$1 ~ /^K|N/ {print $2, $1}' ${file}
     10 echo ""
     11 
     12 echo "Last names starting with C or L:"
     13 awk '$2 ~ /^C|L/ {print $1, $2}' ${file}
     14 echo ""
     15 
     16 echo "Students with their second grade being > 85:"
     17 awk '{if ($5 > 85 && $5 > 85) print}' ${file}
     18 echo ""
     19 
     20 echo "Students in the humanities:"
     21 awk '{if ($3 == "Theo") print}' ${file}
     22 echo ""
     23 
     24 echo "Average ${file}:"
     25 awk '{
     26 sum = cnt = 0;
     27 for (i = 4; i <= NF; i++) {
     28         sum += $i;
     29         cnt++;
     30 }
     31 print $1, $2, sum / cnt}' ${file}
     32 echo ""
     33 
     34 echo "Students with their third grade being < 70:"
     35 awk 'BEGIN {cnt = 0} {if ($6 < 70) cnt++;} END {print cnt}' ${file}
     36 echo ""
     37 
     38 echo "How many student names end in 'is'?"
     39 awk 'BEGIN {cnt = 0} {if ($2 ~ /is$/) cnt++} END {print cnt}' ${file}