I have a series piped greps, awks and seds which produce a list of numbers, one on each line. Something like this:
1.13
3.59
1.23
How can i pipe this to something which will output the average, max, and min?
I have a series piped greps, awks and seds which produce a list of numbers, one on each line. Something like this:
1.13
3.59
1.23
How can i pipe this to something which will output the average, max, and min?
Since you're already using awk
I find this program useful for generating stats on lists of numbers at the command line: http://web.cs.wpi.edu/~claypool/misc/stats/stats.html
There is also simple-r, which can do almost everything that R can, but with less keystrokes:
https://code.google.com/p/simple-r/
To calculate average, max, and min, one would have to type one of:
With a tip of the hat to @DerfK:
perl -lane '$n=$F[0]; if(not defined $min){$min=$max=$n}; if($n>$max){$max=$n}; if($n<$min){$min=$n}; $total+=$n; $count+=1; END{print $total/$count." $max $min"}'
$F[0]
is the value in the first (0'th) field of each lineIf your input data is comma separated, add the
-F,
modifier before-lane
You can use
ministat
:And with
tail
,sed
andcut
you can extract a single field, e.g.ministat -n | tail -1 | sed -r 's/ +/ /g;' | cut -d\ -f 6
gives you the average (since it: takes the last line; removes extra spaces; then takes the sixth non-space token on the line).