rewinding awk 
Author Message
 rewinding awk


Quote:

>If I'm sitting at line n of a file in a script through an awk call, is there
>a way to now read line n-1 of the file without starting back at the
>beginning?  I have the line number from NR and I'm hoping there is some way
>using sed or something else that I can now read previous lines of the file
>without starting from the beginning and wasting that time. mc

If you need to use the prior line, your awk script should have
saved it before doing the next line.

Using something like this as the last line in your script would
be one approach:

{prior=$0}

or using something like this:

{line[NR]=$0}

would make either the prior line, or all read lines accessable.

The later, of course, uses more storage.

Basicly, you cannot backup, but you can store what you might need
as you go by.

Chuck Demas
Needham, Mass.

Inc.
--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Tue, 03 Apr 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Tape drive detach w/o unload rewind

2. Rewinding an input file

3. rewind?

4. PLAY,REWIND,FORWARD,PAUSE ....a WAV File ????

5. DATA and rewind.

6. rewinding a block

7. DATA and rewind

8. rewind the simulation

9. "Rewinding" files in COBOL

10. Rewind

11. How to use REWIND COMMAND of FORTRAN77 in FORTRAN 90

12. rewinding a unit before closing it, why?

 

 
Powered by phpBB® Forum Software