Artificial intelligent assistant

Using awk to extract a value then perform a calculation I have output in a file that looks like this: {tid=4, total=3, column.id=[5.0]} {tid=2, total=1, column.id=[5.0]} {tid=5, total=8, column.id=[5.0]} {tid=8, total=6, column.id=[5.0]} elapsed time: 10 milliseconds current time: Thu Sep 15 16:15:30 This set of output repeats multiple times with different elapsed times. I want to extract the integer representing elapsed time all the times it appears, and then find the average elapsed time. I believe I can get the elapsed time using awk but I am unsure of the correct syntax here.

This should work assuming it's always in milliseconds.


awk '/^elapsed time:/ {T+=$3;C++}; END {print T/C}' test.txt


`/^elapsed time:/` find lines matching desired pattern

`{T+=$3;C++};` add the third column in `T` up and count how many times we do it `C`

`END {print T/C}` print out our average.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 15341996ba64e545d6d4bb5649d8a246