awk reminder
To quickly and easily analyse files or outputs in bash, one can use the powerful awk.
Mean and median calculation
It is easy to compute a mean (for example on the last column of a file):
cat file | awk '{sum += $NF} END {printf "Average: %.3f\n", sum/NR}'
It can be improved to compute standard deviation:
cat file | awk '{sum += $NF; sq += $NF^2} END {printf "Average: %.3f\nStddev: %.3f", sum/NR, sqrt(sq/NR - (sum/NR)^2}'
It is also possible to compute a median; the trick is to first sort the column you intend to analyse:
cat file | awk '{print $NF}' | sort | awk '{a[i++] = $NF} END {printf "Median: %.3f\n", a[int(NR/2)]}'
Find mininum and maximum
The main trick is not to forget to initialise min and max variables:
cat file | awk 'NR == 1 {min = $NF; max = $NF} NR > 1 {min=min<$NF?min:$NF; max=max>$NF?max:$NF+0} END {printf "Min: %.3f\nMax: %.3f\n", min, max}'