How to calculate the average of value in lines of a text file on Linux by a script?
Posted on In QAHow to calculate the average of value in lines of a text file on Linux by a script?
The file.txt is like:
Run 0: Time used: 22.235331711 seconds.
Run 1: Time used: 20.784491219 seconds.
Run 2: Time used: 21.851638876 seconds.
What I want it to calculate the average time.
awk
is handy for this purpose:
awk '{ total += $5; count++ } END { print total/count }' file.txt