解析日志中的某些值

解析日志中的某些值

我正在监控某个问题的收敛历史。历史输出如下:

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

我想做的是在某个时间复制值,例如在本例中Time=26,复制值

Total thrust = -8.51463
Total torque = 1.03953

采用以下格式:

1.03953 -8.51463.

有人可以帮我使用 shell 脚本来做到这一点吗?

答案1

您要求提供 shell 脚本,但希望awk能够做到:

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}

测试一下:

$ 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

答案2

这里我们选出时隙的范围加上下一个(或者 eof,如果它是最后一个)。这样做是为了避免在当前槽没有扭矩/推力数的情况下抓取下一个槽的数据。因此,您将获得陈旧的数据,并且不会出现任何错误报告。该H命令将模式空间附加到保留空间。g将检索保留区域并将其放入模式空间中。

tslot=26; # input the time you want the thrust/torque data for
sed -ne '
   /^Time = '"${tslot}"'$/,/^Time =/!d
   /^Total thrust =/{H;d;}
   /^Total torque =/{H;d;}
   g;/\n.*\n/!d
   /thrust.*torque/s/\(\n.*\)\(\n.*\)/\2\1/
   s/\n[^=]*=//gp;q
' logfile

结果

1.03953 -8.51463

相关内容