Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi,
I have one file, say file 1, that has data like below where 19900107 is the date,

19900107          12         144         129   0.7380047    
19900108          12         168         129   0.3149017    
19900109          12         192         129   3.2766666E-02
19900110          12         216         129  -2.0089082E-02
19900111          12         240         129  -0.3891007    
19900107          12         120         151   0.8195071

I want to extract all info from this file , and send it to file 2, that has a line with "240" and a value at the end between 0.8 and 1. Any line that matches this criteria i also want to extract the previous 5 lines of data (i.e. the previous 5 dates). All any any help is appreciated. I'm a new linux user. :rolleyes:

awk '{v=w;w=x;x=y;y=z;z=$0}$3==240&&($NF>=0.8)&&($NF<=1){print v"\n"w"\n"x"\n"y"\n"z}' infile

use nawk or /usr/xpg4bin/awk instead of awk if running SunOS or Solaris

awk -v x=120 -v y=0.8 -v z=1 '{a[NR]=$0}$3==x && $NF>=y && $NF<=z{for(i=(NR-5);i++<NR;) print a}' file > newfile

Thanks very the prompt reply

that works perfect