Just for the sake of having a variety of options presented, I've put together on this page, Here are two more ways:
1: "bash + single-purpose tools"octave method.
- GNU Octave is a high-level interpreted language, primarily intended for numerical computations. It provides capabilities for the numerical solution of linear and nonlinear problems, and for performing other numerical experiments.
I like bash, but for this particular purpose I'll probably use Rscript; itHere is just so terse, and it will be handy for other more involved mathematical jobs.a quick octave example.
octave -q --eval 'A=1:10; printf ("# %f\t%f\t%f\t%f\n", min(A), max(A), median(A), mean(A));' # 1.000000 10.000000 5.500000 5.500000 2: bash + single-purpose tools.
For bash to handle floating-point numbers, this script uses numprocess and numaverage from package num-utils.
PS. I've also had a reasonable look at bc, but for this particular job, it doesn't offer anything beyond what awk does. It is (as the 'c' in 'bc' states) a calculator—a calculator which requires a much programming as awk and this bash script...
arr=($(sort -n "LIST" |tee >(numaverage 2>/dev/null >stats.avg) )) cnt=${#arr[@]}; ((cnt==0)) && { echo -e "0\t0\t0\t0\t0"; exit; } mid=$((cnt/2)); if [[ ${cnt#${cnt%?}} == [02468] ]] then med=$( echo -n "${arr[mid-1]}" |numprocess /+${arr[mid]},%2/ ) else med=${arr[mid]}; fi # count min max median average echo -ne "$cnt\t${arr[0]}\t${arr[cnt-1]}\t$med\t"; cat stats.avg