Parse logs for certain values

logstext processing

I am monitoring the history of convergence of a certain problem. The history output is as follows:

Time = 24

Calculate volume forces from actuator disk
Total thrust = -8.46832
Total torque = 1.03471
ADisk volume = 0.0632799
smoothSolver:  Solving for Ux, Initial residual = 0.000447755, Final residual = 2.68745e-05, No Iterations 2
smoothSolver:  Solving for Uy, Initial residual = 0.0107909, Final residual = 0.000812227, No Iterations 2
smoothSolver:  Solving for Uz, Initial residual = 0.0103399, Final residual = 0.000786661, No Iterations 2
GAMG:  Solving for p, Initial residual = 0.123954, Final residual = 0.00958268, No Iterations 6
time step continuity errors : sum local = 7.42808e-05, global = -4.25546e-05, cumulative = 0.000413527
smoothSolver:  Solving for epsilon, Initial residual = 0.00197379, Final residual = 0.000172248, No Iterations 1
smoothSolver:  Solving for k, Initial residual = 0.000510499, Final residual = 2.78594e-05, No Iterations 2
ExecutionTime = 124.63 s  ClockTime = 125 s

Time = 25

Calculate volume forces from actuator disk
Total thrust = -8.49093
Total torque = 1.03723
ADisk volume = 0.0632799
smoothSolver:  Solving for Ux, Initial residual = 0.000409002, Final residual = 2.59552e-05, No Iterations 2
smoothSolver:  Solving for Uy, Initial residual = 0.0103191, Final residual = 0.00077024, No Iterations 2
smoothSolver:  Solving for Uz, Initial residual = 0.00985658, Final residual = 0.000742227, No Iterations 2
GAMG:  Solving for p, Initial residual = 0.0390756, Final residual = 0.00247253, No Iterations 7
time step continuity errors : sum local = 5.39785e-05, global = 3.40394e-05, cumulative = 0.000447566
smoothSolver:  Solving for epsilon, Initial residual = 0.00182397, Final residual = 0.000157739, No Iterations 1
smoothSolver:  Solving for k, Initial residual = 0.000465916, Final residual = 2.75864e-05, No Iterations 2
ExecutionTime = 129.45 s  ClockTime = 130 s

Time = 26

Calculate volume forces from actuator disk
Total thrust = -8.51463
Total torque = 1.03953
ADisk volume = 0.0632799

What I would like to do, is to copy values at a certain time, say in this case at Time=26, the values of

Total thrust = -8.51463
Total torque = 1.03953

in the following format:

1.03953 -8.51463.

Can someone help me to do that using shell script.

Best Answer

You asked for a shell script, but hopefully awk will do:

find_thrust_torque.awk:

/^Total thrust =/ {thrust = $4}
/^Total torque =/ {torque = $4}
/^Time =/ {if (found) exit; if ($3 == time) found=1}
END {print torque " " thrust}

Test It:

$ awk -v time=25 -f find_thrust_torque.awk file1
1.03723 -8.49093

$ awk -v time=26 -f find_thrust_torque.awk file1
1.03953 -8.51463
Related Question