How to calculate the average of value in lines of a text file on Linux by a script?

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

asked Jun 7, 2014 by Eric Z Ma (44,280 points)

1 Answer

 
Best answer

awk is handy for this purpose:

awk '{ total += $5; count++ } END { print total/count }' file.txt
answered Jun 7, 2014 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...