grabing a number six lines below a pattern

前端 未结 4 1094
耶瑟儿~
耶瑟儿~ 2021-01-20 16:19

I have these lines repeating

                               FINAL RESULTS



    NSTEP       ENERGY          RMS            GMAX         NAME    NUMBER
    1         


        
相关标签:
4条回答
  • 2021-01-20 17:09

    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.

    0 讨论(0)
  • 2021-01-20 17:10

    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
    
    0 讨论(0)
  • 2021-01-20 17:16

    Something like this should work for you:

    awk '/FINAL RESULTS/{for (i=0; i<5; i++) getline; print $2}' <filename>
    
    0 讨论(0)
  • 2021-01-20 17:17

    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).

    0 讨论(0)
提交回复
热议问题