I have a log file having a output:
Time = 1
smoothSolver: Solving for Ux, Initial residual = 0.230812, Final residual = 0.0134171, No Iterations 2
smoothSolver: Solving for Uy, Initial residual = 0.283614, Final residual = 0.0158797, No Iterations 3
smoothSolver: Solving for Uz, Initial residual = 0.190444, Final residual = 0.016567, No Iterations 2
GAMG: Solving for p, Initial residual = 0.0850116, Final residual = 0.00375608, No Iterations 3
time step continuity errors : sum local = 0.00999678, global = 0.00142109, cumulative = 0.00142109
smoothSolver: Solving for omega, Initial residual = 0.00267604, Final residual = 0.000166675, No Iterations 3
bounding omega, min: -26.6597 max: 18468.7 average: 219.43
smoothSolver: Solving for k, Initial residual = 1, Final residual = 0.0862096, No Iterations 2
ExecutionTime = 4.84 s ClockTime = 5 s
I need to extract cumulative = 0.00142109 (which is in line 5 of the about output) using Python's regular expression. More precisely, I need to extract only the value 0.00142109 that corresponds to cumulative and write to an another file.
Currently, this is what I have:
contCumulative_0_out = open('contCumulative_0', 'w+')
with open(logFile, 'r') as logfile_read:
for line in logfile_read:
line = line.rstrip()
if re.findall('cumulative = ([+-]?\d+)(?:\.\d+)?(?:[eE][+-]?\d+)?', line):
print line
contCumulative_0_out.write(line)
However, the output with the above code is:
time step continuity errors : sum local = 0.00999678, global = 0.00142109, cumulative = 0.00142109
I am basically getting the entire line that matches cumulative
Please let me know how to extract only the value corresponding to cumulative.