[Chapter 25] 25.19 Reverse Lines in Long Files with flip
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:43:31Z

#

| Chapter 25 Showing What's in a File |

## 25.19 Reverse Lines in Long Files with flip

If you're looking at a long log file and you want to see the most recent lines first, you might use the tail -r (25.15) command. It shows the lines of a file in reverse order, last line first. It will give up if your file is too big, though. How big "too big" is depends on your version of tail. To find out, try a very big text file and see how far tail -r goes:

>     % tail -r /usr/dict/words > /tmp/words.tailr
>     % ls -l /tmp/words.tailr /usr/dict/words
>     -rw-r--r--  1 jerry       32768 Dec  5 09:49 /tmp/words.tailr
>     -rw-r--r--  1 root       206672 Feb  8  1990 /usr/dict/words

flip | tail -r quit after 32768 characters on our system. The flip program has no theoretical limit, but it needs enough system memory to hold your file (or its standard input). Here it is, courtesy of Tom Christiansen:

>     #!/usr/local/bin/perl
>     print reverse <>

- JP

25.18 Watching Several Files Grow |  | 25.20 Printing the Top of a File