I have a log file which has below structure. I would like to get information after the "Initial residual = " text in each line and export it to a .txt file.
Time = 1996
smoothSolver: Solving for Ux, Initial residual = 0.000674461, Final residual = 9.44251e-07, No Iterations 5
smoothSolver: Solving for Uy, Initial residual = 0.00478922, Final residual = 7.06574e-07, No Iterations 7
GAMG: Solving for p, Initial residual = 0.00899, Final residual = 9.67531e-07, No Iterations 10
time step continuity errors : sum local = 2.63988e-05, global = 4.03835e-06, cumulative = -1.29495e-05
smoothSolver: Solving for epsilon, Initial residual = 0.00209075, Final residual = 3.67614e-07, No Iterations 6
smoothSolver: Solving for k, Initial residual = 0.0017321, Final residual = 9.33393e-07, No Iterations 6
ExecutionTime = 27.9 s ClockTime = 28 s
Time = 1997
smoothSolver: Solving for Ux, Initial residual = 0.000659293, Final residual = 9.46747e-07, No Iterations 5
smoothSolver: Solving for Uy, Initial residual = 0.00479541, Final residual = 7.03185e-07, No Iterations 7
GAMG: Solving for p, Initial residual = 0.00975341, Final residual = 9.64034e-07, No Iterations 10
time step continuity errors : sum local = 2.6336e-05, global = 3.87822e-06, cumulative = -9.07129e-06
smoothSolver: Solving for epsilon, Initial residual = 0.00213882, Final residual = 3.64484e-07, No Iterations 6
smoothSolver: Solving for k, Initial residual = 0.00172913, Final residual = 9.36427e-07, No Iterations 6
ExecutionTime = 27.91 s ClockTime = 28 s
The .txt file will have below structure
1996 0.000674461 0.00478922 0.00899 0.00209075 0.0017321
1997 0.000659293 0.00479541 0.00975 0.00213882 0.0017291
.
.
With grep I can find the lines which contain a certain string. Then I can use cut to extract numbers at a certain column location and write it in a text file. For example, I am using the below command to extract information from lines that contain a specified string :
cat log | grep 'Solving for Ux' | cut -d' ' -f9 | tr -d ',' > resy.txt
cat log | grep 'Solving for Uy' | cut -d' ' -f9 | tr -d ',' > resy.txt
But I wanted to check if there is any other way in which I can extract all the information corresponding to two strings together. Thank you.