how to read previous line 
Author Message
 how to read previous line

  > Using awk from a k-shell script, I am in my pattern{action} script sitting
at

Quote:
> line #n.  I now want to step back and see what is in line #n-x.  I tried
> setting NR to the desired line number and doing getline but that didn't work.

  If x is fixed, then you could save #n-x in a variable:  say x=5 (i.e. not too
large)

awk '{ previous[NR%6]=$0 }
{ whatEverYouDo++ }'

Thus you have availabeleprevious[0], previous[1]...previous[5]
cyclically containing the last 6 lines including the current line.
The statement saving $0 should be first, in case you do such a
thing as $1++ ...

You can use now such things as

if( previous[(NR-5)%6]~/liberal/ ) { print "ALERT" }

LMS
free sed/awk book:
      ftp://ftp.u-aizu.ac.jp/u-aizu/doc/Tech-Report/1997/97-2-007.ps.gz
      ftp://ftp.u-aizu.ac.jp/u-aizu/doc/Tech-Report/1997/97-2-007.tar.gz



Wed, 04 Apr 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. reading previous line using expect

2. Previous Line

3. how to grep previous line in file ?

4. Newbie needing help to print previous lines...

5. Inserting text from a previous line?

6. Can I read previous test data into Labview?

7. Read Previous???

8. READ PREVIOUS and ESQL

9. READ PREVIOUS - immediately after an OPEN

10. READ PREVIOUS IN BATCH COBOL ?

11. error reading data: OMMIT Previous post ()

12. reading a line and executing a command on that line

 

 
Powered by phpBB® Forum Software