Home > Software engineering >  AWK apply to all the rows except first few
AWK apply to all the rows except first few

Time:04-19

I want a report xyz.rpt in the below format

ajsh askj sdjh 54 12
jhgj 765 2839
 kjsd sdh sdsdf sdffsdf sdff 
 5464 765 67     65      76
 2356 423 34     45      34

and so on

I want to print first 2 header line also along with the output of awk command.

awk '{if ( $5 < 65  ) print}' > aaa.rpt

CodePudding user response:

One awk idea:

awk '
FNR<=2                          # print 1st 2 lines
FNR>2 && $5 0==$5 && $5<65      # print lines where $5 is numeric and $5 < 65
' xyz.rpt

Or as a one-liner:

awk 'FNR<=2; FNR>2 && $5 0==$5 && $5 < 65' xyz.rpt

This generates:

ajsh askj sdjh 54 12
jhgj 765 2839
 2356 423 34     45      34

CodePudding user response:

not as elegant as i hoped

nawk '($5== $(5*( $5<=4^3))) (3>FNR)'

ajsh askj sdjh 54 12
jhgj 765 2839
 2356 423 34     45      34

CodePudding user response:

$ awk 'NR<=2 || ($5 0==$5 && $5<65)' file  
  • Related