In bash I can grep some time measurements from a log file like this
grep "time:" myLogfile.txt | cut -d' ' -f 3 >> timeMeasurements.txt
#timeMeasurements.txt
2.5
3.5
2.0
...
Now I would like to compute the mean value from the values in timeMeasurements.txt
. What is the quickest way to do that in bash?
I know that there is gnuplot and R but it seems like one has to write some lengthy script for either one on them.
Best Answer
Another way, using
sed
andbc
:The sed expression converts the input to something like this:
This is piped to
bc
which evaluates it line-by-line.