【发布时间】:2018-11-08 15:32:54
【问题描述】:
我需要使用 grep 从具有以下格式的一系列行中提取数值:“总差值为:11.7423485766”。
这里是文件的格式
smoothSolver: Solving for Uax, Initial residual = 0.00117823324374, Final residual = 2.6551659504e-06, No Iterations 4
smoothSolver: Solving for Uay, Initial residual = 0.00102460810826, Final residual = 2.27551114222e-06, No Iterations 4
GAMG: Solving for pa, Initial residual = 0.083060886073, Final residual = 4.42348716834e-05, No Iterations 8
Adjoint continuity errors : sum local = 0.000102057393701, global = -2.79342190934e-05, cumulative = -0.00156476995631
The ratio scalar is 0.00767871345324
The toal volume is 0.01
The percentage of fluid domain is 0.767871345324
omegaVol is 1.331
Total Pressure at the inlet: 18.3146365858
Total Pressure at the outlet: 0.533553352625
The total difference is: 17.7810832332
ExecutionTime = 1.05 s
我试过了
grep "The total difference is:" | cut -d' ' -f9 log
但它似乎不起作用,我不明白为什么。
有什么想法吗?感谢您的帮助
【问题讨论】:
-
如果我理解正确,你应该使用 grep "The total difference is:" |剪切 -d' ' -f5 日志
-
您好@M.Falzone 感谢您的快速回复。也许我应该添加我的文件的组成方式。我刚刚更新了主线程。
-
您的例句包含 5 个空格分隔的字段,但您正在尝试获取第 9 个字段。这是完整的输入行吗?
-
@BenjaminW。我刚刚更新了格式文件