Grep号码提取 [英] Grep number extraction

查看:77
本文介绍了Grep号码提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用grep从一系列具有以下格式的行中提取数值:总差为:11.7423485766".

I need to extract the numerical value, using grep, from a series of lines with this format: "The total difference is: 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

但是它似乎不起作用,我也不明白为什么.

but it seems not to work and I don't understand why.

有什么主意吗?感谢您的帮助

Any idea? Thanks for help

推荐答案

这是怎么回事:

grep "The total difference is:" log | grep -o "[0-9.]*"

第一个grep占据整行,包含匹配的文本,第二个grep仅占据数字.

The first grep takes the entire line, containing the matching text, the second one takes only the digits.

这篇关于Grep号码提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆