start page | rating of books | rating of authors | reviews | copyrights

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 25.18 Watching Several Files Grow Chapter 25
Showing What's in a File
Next: 25.20 Printing the Top of 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


Previous: 25.18 Watching Several Files Grow UNIX Power ToolsNext: 25.20 Printing the Top of a File
25.18 Watching Several Files Grow Book Index25.20 Printing the Top of a File

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System