Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grabing a number six lines below a pattern

I have these lines repeating

                               FINAL RESULTS



    NSTEP       ENERGY          RMS            GMAX         NAME    NUMBER
    1000      -4.7910E+01     2.1328E-01     9.4193E-01     C          62

The FINAL RESULTS indicate a average of those values for a set. The output file combines all 1000 sets. I need to grab the number below energy (-4.7910E+01), all 1000 of them in to another file. I need to set FINAL RESULTS as a pattern because other pattern such as NSTEP, ENERGY, RMS.... are repeated in millions.

I'll be grateful for any help.

like image 959
do yong kim Avatar asked Mar 05 '26 05:03

do yong kim


2 Answers

Something like this should work for you:

awk '/FINAL RESULTS/{for (i=0; i<5; i++) getline; print $2}' <filename>
like image 173
jcollado Avatar answered Mar 08 '26 00:03

jcollado


OK, I think I see now.

awk 'found==1 { print $2; found=0 } $2=="ENERGY" { found=1 }' inputfile

This will get the number below ENERGY regardless of how many lines there are between it and FINAL RESULTS.

like image 37
Kevin Avatar answered Mar 08 '26 02:03

Kevin