AWK - Printing ALL lines after a pattern match

classic Classic list List threaded Threaded
4 messages Options
Sam
Reply | Threaded
Open this post in threaded view
|

AWK - Printing ALL lines after a pattern match

Sam
Hello,
I have a file that contains following information:


                                *** REGIONS ***
                                                                         
                                 Region                       Def      
 Region                       Area                         Popl    
 -----------------------------------------------------------------------
 NE                             NE                                0    
 SE                             SE                                0    

I would like to print first column of all the lines after a pattern match of '-'. I have the following command:

cat <file name> |  awk '/-/ {x=NR+10;next}(NR<=x){print $1}'

however the number of rows and columns in the file are variable in nature (the first 3 columns will always be there). are there any suggestions on how to go about it?

thanks
Sam
Reply | Threaded
Open this post in threaded view
|

Re: AWK - Printing ALL lines after a pattern match

Guru
Administrator
awk '/^ -/{x=1;next}x{print $1}' file
Sam
Reply | Threaded
Open this post in threaded view
|

Re: AWK - Printing ALL lines after a pattern match

Sam
Guru,
Many many thanks.
-Sam
Reply | Threaded
Open this post in threaded view
|

Re: AWK - Printing ALL lines after a pattern match

Jean-Paul
You can even find shorter :
  awk 'NR==1,/-/{next}{print $1}' file.txt