This one is asked many times and still I am unable to solve. A part of my file looks like:
GKKRBSF:: ewrat= 0.00000 (<1 searchk, >1 searche)
dirat= 0.00000 (Direct Summation ratio)
nhat,betah= 0.1000D+01 0.0000D+00 0.1000D+01 0.10000D+00
nhat,betah= 0.1000D+01 0.0000D+00 0.1000D+01 0.10000D+00
nhat,betah= 0.1000D+01 0.0000D+00 0.1000D+01 0.10000D+01
nhat,betah= 0.1000D+01 0.0000D+00 0.1000D+01 0.10000D+01
nhat,betah= 0.1000D+01 0.0000D+00 0.1000D+01 0.10000D+00
This is somewhere in between the file. I have to get $5 of first and n-th(say,3rd in this particular example) match of nhat,betah
.
For the first line, I can easily do a:
var_M=`awk '/nhat,betah=/{print $5;exit}' filename`
But, how can I get the 3rd line and exit? I tried, from this thread, as:
var_M=`awk '/nhat,betah=/{j++}j=3{print $5;exit}' filename`
And this is giving the 5th column of the 3rd line of the file, without matching the pattern. Surely I am missing something. Any help please?