I have a huge log file (about 6GB) from a simulation. Among the millions of lines in that file, there are two lines that are frequently repeating for a given time:
...
Max value of omega = 3.0355
Time = 0.000001
....
Max value of omega = 4.3644
Time = 0.000013
...
Max value of omega = 3.7319
Time = 0.000025
...
...
...
Max value of omega = 7.0695
Time = 1.32125
...
... etc.
I would like to extract both "Max value of omega" and "Time" and save them in a single file as columns:
#time max_omega
0.000001 3.0355
0.000013 4.3644
0.000025 3.7319
...etc.
I proceeded as follows:
# The following takes about 15 seconds
grep -F 'Max value of omega' logfile | cut -d "=" -f 2 > max_omega_file.txt
, and the same for "Time"
# This also takes about 15 seconds
# Very important: match exactly 'Time =' because there other lines that contain the word 'Time'
grep -F 'Time =' logfile | cut -d "=" -f 2 > time.txt
Then I need to use the command paste
to create a two-columns file: Time.txt as the first column and "max_omega_file.txt" as the second column.
As you can see, the time is doubled in the steps above. I wonder if there a single solution to achieve the same results in a single pass so I save some time?
^Max
regex is not sufficient because there also lines like 'Max iterations' ...etc. The same thing with Time, I want to find literally "Time =" to get the expected line. – adhrar_nmatrous Nov 21 '20 at 14:51//
to repeat last match which might allow some shorthand here./^Max.*=\s*/s///h;/^Time.*=\s*/{s///G;s/\n/ /p;}
– stevesliva Nov 22 '20 at 04:40