#! /bin/sh # Calculate total points awarded so far total=0 for i in ${1:-answers}/*; do pts=$(awk '{print $2; exit;}' $i) total=$(expr $total + $pts) done render () { name=$1 cat=$2 score=$3 width=$(awk "BEGIN{print 100 * $score / $total;}") printf '%d' \ $cat $width $name $cat $score $name $cat $score $score } scores () { cat= score=0 while read c p; do if [ "$cat" != "$c" ] && [ $score -gt 0 ]; then render $1 $cat $score score=0 fi cat=$c score=$(expr $score + $p) done if [ $score -gt 0 ]; then render $1 $cat $score fi } cat < Project 2 Scoreboard

EOF for dn in /opt/*/answers.txt; do c=$(echo $dn | cut -d/ -f2) printf '%s\n' $c $c done cat <

EOF for d in users/*; do awk -v d=$d '{s+=$2;} END{print s " " d;}' $d/* 2>/dev/null done | sort -nr | while read s d; do user=${d##*/} echo '

' printf '%s\n' $user sort $d/* 2>/dev/null | scores $user echo echo '

' done cat < EOF