#!/bin/sh col="none" if [ $# -ge 1 ]; then if [ a"$1" = a-c ]; then if [ $# -eq 1 ]; then echo 'usage: calcavg [ -c n ] [ files ]' >&2 exit 1 fi if [ "$2" -le 0 ]; then echo 'usage: calcavg [ -c n ] [ files ]' >&2 exit 1 fi col=$2 shift ; shift fi fi if [ $# -eq 0 ]; then fn='-' else fn=$* fi if [ $col = none ]; then s='for (i = 1; i <= NF ; i++) {' else s="i = $col ; if (NF >= $col) {" fi cat $fn | awk 'BEGIN { n = 0; t = 0 } { '"$s"' n++ ; t += $i }} END { if (n == 0) print "inf" ; else print t/n }'