grabing a number six lines below a pattern

一曲冷凌霜 提交于 2019-12-01 21:10:35

Something like this should work for you:

awk '/FINAL RESULTS/{for (i=0; i<5; i++) getline; print $2}' <filename>

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!