How to read lines backwards from a file?

How to read lines backwards from a file?

Post by P K Sh » Tue, 20 Dec 1994 06:10:32



What is the best way to read text lines backwards
from a text file? I am trying to avoid writing
some kind of buffer management support so that I
can seek forward and backward in a text file by line.

--
= P.K. Shiu ===========================================

 
 
 

How to read lines backwards from a file?

Post by Ruurd Beerst » Fri, 23 Dec 1994 00:05:44



: What is the best way to read text lines backwards
: from a text file? I am trying to avoid writing
: some kind of buffer management support so that I
: can seek forward and backward in a text file by line.

Awk (or perl) is your friend, me thinks. The AWK script:
        { Buf[NR] = $0 }
END     { for (i = NR; i > 0; i--)
             print Buf[i]
        }

prints out its input in reverse order. This does mean, however,
that the entire file is buffered in memory. Don't try it with
files that are much larger then your machines memory.

Hope this helps,
        Ruurd.
--
========================================================================
Ruurd Beerstra, CMG-IT, Netherlands. | #include <stddisclaimer.h>

                                     | what is he doing on my hard disk?

 
 
 

1. read from stdin while reading line by line a file

while read line ; do
    // I need to read input from the user
    read INPUT
done < file.txt

the problem is that it is not going through "read INPUT"

any workaround?

thanks for all your help. I really appreciate it
matias

2. need monitor record for NEC-6FG

3. Reading a file backwards

4. cu -p? -s14400

5. How to read line by line of a file

6. 2.0.0 woes

7. HELP: How do I read a file line-by-line without getting spaces stripped?

8. Problem with fvwm-95??

9. read a file line by line

10. How to read line by line from a file?

11. Read a file line after line

12. reading files line-be-line?

13. Line by line file read