I have these lines repeating
FINAL RESULTS
NSTEP ENERGY RMS GMAX NAME NUMBER
1
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
.
This might work for you:
awk '/FINAL RESULTS/{f=1;p=0}{p++}f==1 && p==6{print $2}' file
Or if you like:
awk 'f==2 && p==1{print $2}{p++}/FINAL RESULTS/{f=1}/ENERGY/ && f==1{f=2;p=0}' file
Something like this should work for you:
awk '/FINAL RESULTS/{for (i=0; i<5; i++) getline; print $2}' <filename>
With GNU grep
(and some others following its extensions) you could just do something like grep -A 6 'FINAL RESULTS'
So that should work for Linux, and I see that it works on a recent MacOS X and I'm pretty sure I've used it on FreeBSD. So it probably works on most forms of UNIX you're going to encounter. (If not, install the GNU "coreutils" package).