The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 02-09-2009
jolecanard jolecanard is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 36
Cool Error in multiple files treatment with AWK

Hello,

My code is like that:

Code:
 
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:
Code:
...
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