Improving on yesterday’s mean value calculator
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:
- awk '
- BEGIN {
- FS=","
- total = 0
- count = 0
- }
- {
- total = total + $2
- count++
- }
- END {
- if(count> 0) { print total/count } else { print "n/a" }
- }'
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. ![]()

so what’s the point? – _-;;
Comment on September 22, 2008 @ 20:34:46
I often have non, it’s part of my refreshing personality.
Hmm, here I did fix the divide by zero bug though. 
Comment on September 24, 2008 @ 23:40:48