Error in multiple files treatment with AWK

Hello,

My code is like that:

 
awk -v f=92238 '$1~/^m2/{tok1=1;next}tok1==1&&$0~f{tok1=0;print $NF}' inp.[1-9] inp.1[0-5]

Eahc of the "inp.*" file is like that:

...
m1 xxxx xxxx
     92238 897987
     xxxx xxxx
m2 xxxx xxxx
     92238 123435
     xxxx xxxx
...

The problem is that it returns me both the value in m1 and m2 (I asked only for the values in m2).

Any idea why my script does not return the expected result?

Thanks

Finally I found!! Just posting the message helped me figuring out the solution:

In the end of the first read file, it found an occurence of ^m2 (m201), and then when it closes the first file and opens the second one, it keeps looking for "92238", and it finds it in the block "m1".

To solve this problem, just need to use ^m2$ instead of ^m2 .:smiley: