There are still some bugs in yesterday's bash script. For example there is a nasty condition in the awk part. What happens if the mean value of an empty file is calculated? Awk of course complains "fatal: division by zero attempted".

Improvement:

BASH:
  1. awk '
  2. BEGIN {
  3.   FS=","
  4.   total = 0
  5.   count = 0
  6. }
  7. {
  8.   total = total + $2
  9.   count++
  10. }
  11. END {
  12.   if(count> 0) { print total/count } else { print "n/a" }
  13. }'

And there are of course some interesting side effects in the command parsing snippet. But that's for another day, I guess. Because improving that will require some real array voodoo. :-)