I'm looking at averaging a number of data points given from multiple runs of a command. In this particular case, I'm using the sysbench
tool suite.
This example input is from a single sysbench cpu <parameters>
run; keep in mind this will be run multiple times as I'm looking to average certain results:
CPU speed:
events per second: 827.81
General statistics:
total time: 30.0021s
total number of events: 44977
Latency (ms):
min: 2.01
avg: 4.93
max: 733.85
95th percentile: 12.98
sum: 228990.08
In my example script
(for ((n=0;n<3;n++)); do
<command> | grep -i <data point lines>;
done) | awk '{ print $(NF) }'
I grab the relevant data points from each run and print (as a placeholder for whatever code I will use) the last field of each line below. This contains numbers I need to work with. What I need is something that will add every nth $(NF) together and then average them, which I can already conceptualize.
Let's say from that example I want to take these points (via grep currently but not fussed on implementation)
events per second: 827.81
avg: 4.93
max: 733.85
95th percentile: 12.98
And take the last column from them (via awk '{ print $(NF) }' currently)
827.81
4.93
733.85
12.98
Assuming 4 lines of output per cycle and n cycles I want to add all lines matching the same field (so all avg:'s are summed and averaged, same for max: and other stats.)
add lines 1/5/9/4n
2/6/10/4n
3/7/11/4n
4/8/12/4n
together
I'm trying to use awk (as this code will be used over multiple unix systems and awk is a common factor) but if I'm overcomplicating this and there is a better alternative I'm happy to hear it.