Reputation: 69
I need to extract the numerical value, using grep, from a series of lines with this format: "The total difference is: 11.7423485766".
Here the format of the file
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
I tried
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
Upvotes: 0
Views: 64
Reputation: 51928
Dominique's answer is correct. Just for completeness, your error is, that you specify no file for grep. So you enter interactive mode of grep.
When you do it like this it works:
grep "The total difference is:" log | cut -d' ' -f5
P.S.: you were also selecting the wrong field. It's 5, not 9.
Upvotes: 3
Reputation: 17565
What about this:
grep "The total difference is:" log | grep -o "[0-9.]*"
The first grep
takes the entire line, containing the matching text, the second one takes only the digits.
Upvotes: 3