Problems to print specific lines with awk and grep...HELP!

Hi all

I have data like this:

model:    1,   misfit value:   0.74987
 
       1     1.182     1.735     2.056     1.867
 
       2     0.503     1.843     2.018     1.888
 
       3     2.706     2.952     2.979     1.882
 
       4     8.015     3.414     3.675     1.874
 
       5     1.557     3.745     3.238     1.776
 
       6     7.380     3.843     4.596     1.885
 
model:    2,   misfit value:   0.86908
 
       1     0.921     1.748     2.055     1.889
 
       2     0.402     2.465     1.913     1.808
 
       3     2.082     2.934     3.229     1.893
 
       4     9.872     3.294     3.747     1.704
 
       5     0.592     3.863     3.513     1.795
 
       6    16.299     4.028     4.551     1.890

and I want to print specific lines if a pattern occured. I've tried with awk and grep command but it doesn't work well.

I want to print the line with the misfit value and the next six lines if misfit value is less than some specific value. I tried with:

grep "misfit value" rfi_models | awk '{if ($5<0.8 print $0}' 

but this print only the line with the misfit value.

grep -A6 -B1 "misfit value" rfi_models

and this print all the models without if statement...

Please can you suggest me something?

Thanks

Assuming no blank lines between the records (unlike the provided sample):

awk '/misfit value/ && $5 > 0.8 { c = 7 } c && c--' infile
1 Like