Skip to main content
added 366 characters in body; added 2 characters in body; deleted 2 characters in body
Source Link
Peter.O
  • 33.8k
  • 32
  • 120
  • 167

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 

Just for the sake of having a variety of options presented, I've put together this "bash + single-purpose tools" method.

I like bash, but for this particular purpose I'll probably use Rscript; it is just so terse, and it will be handy for other more involved mathematical jobs...

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 

Just for the sake of having a variety of options presented on this page, Here are two more ways:

1: octave

  • 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.

Here is 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 
added 177 characters in body; added 64 characters in body; added 14 characters in body; deleted 1 characters in body
Source Link
Peter.O
  • 33.8k
  • 32
  • 120
  • 167

Just for the sake of having a variety of options presented, I've put together this "bash + single-purpose tools" method.

I like bash, but for this particular purpose I'll probably use Rscript; it is just so terse, and it will be handy for other more involved mathematical jobs...

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 

Just for the sake of having a variety of options presented, I've put together this "bash + single-purpose tools" method.

I like bash, but for this particular purpose I'll probably use Rscript; it is just so terse, and it will be handy for other more involved mathematical jobs...

For bash to handle floating-point numbers, this script uses numprocess and numaverage from package num-utils.


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 

Just for the sake of having a variety of options presented, I've put together this "bash + single-purpose tools" method.

I like bash, but for this particular purpose I'll probably use Rscript; it is just so terse, and it will be handy for other more involved mathematical jobs...

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 
deleted 64 characters in body
Source Link
Peter.O
  • 33.8k
  • 32
  • 120
  • 167

Just for the sake of having a variety of options presented, I've put together this "bash + single-purpose tools" method.

I like bash, but for this particular purpose I'll probably use Rscript; it is just so terse, and it will be handy for other more involved mathematical jobs...

For bash to handle floating-point numbers, this script uses numprocess and numaverage from package num-utils.


arr=($(sort -n "LIST" |tee >( numaverage 2>/dev/null >stats.avg ) | while IFS= read -r numb ;do echo "$numb"; done )) 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 

Just for the sake of having a variety of options presented, I've put together this "bash + single-purpose tools" method.

I like bash, but for this particular purpose I'll probably use Rscript; it is just so terse, and it will be handy for other more involved mathematical jobs...

For bash to handle floating-point numbers, this script uses numprocess and numaverage from package num-utils.


arr=($(sort -n "LIST" |tee >( numaverage 2>/dev/null >stats.avg ) | while IFS= read -r numb ;do echo "$numb"; done )) 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 

Just for the sake of having a variety of options presented, I've put together this "bash + single-purpose tools" method.

I like bash, but for this particular purpose I'll probably use Rscript; it is just so terse, and it will be handy for other more involved mathematical jobs...

For bash to handle floating-point numbers, this script uses numprocess and numaverage from package num-utils.


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 
added 61 characters in body
Source Link
Peter.O
  • 33.8k
  • 32
  • 120
  • 167
Loading
Source Link
Peter.O
  • 33.8k
  • 32
  • 120
  • 167
Loading