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

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 25.4 The "less" Pager: More than "more"Chapter 25
Showing What's in a File
Next: 25.6 What's in That White Space?
 

25.5 Page Through Compressed, RCS, Unprintable Files

zmore
Compressed (24.7) files save disk space. But compressed files aren't as convenient to work with: you have to uncompress them before you can read or edit them. The zmore script (also named zpg and zless) makes the job easier. It uncompresses one or more files and feeds them to a pager: more (25.3), pg, or less (25.4). (The script uses GNU gzcat, which can read both gzip and compress format.) The script can also page through files that have been made printable by cat -v -t -e (25.7, 25.6). This is a safe way to page through files that might have unprintable characters that could mess up your terminal if they weren't filtered. Finally, the script can page through the latest revision of an RCS file (20.14).

Here's an example. Let's page through the gzipped files data.gz and ../summary.gz. Then we'll read the suspiciously named file Ex034912 to see what's in it:

% zmore data ../summary      You don't need to type the .gz

   ...First screen of data.gz, uncompressed...

--More--

   ...The rest of data.gz, uncompressed...

zmore: Press RETURN to see next file, '../summary':

   ...First screen of ../summary.gz, uncompressed...

% vmore Ex034912

   ...First screen of Ex034912, filtered with cat -t -v -e...

The same script file does all those things. It's written to have eight other links (18.3): zpg, zless, vmore, vpg, vless, rcsmore, rcspg, and rcsless. The script tests the name it was called with, from $0, to decide whether to use gzcat, cat -t -v -e, or co -p, and which pager to run. This trick saves disk space. You can change the pagers used by modifying the script and adding or removing links to it. The absolute pathnames at the start of the script may need to be changed for your system.

Most pager programs can't back up or move around as easily when they're reading from a pipe. (less can.) You can use a temporary file instead. That's not as efficient as using a pipe, but it's good to be able to do. To do that, add the following two lines after the second case statement:

/tmp..$$ 
trap 
temp=/tmp/$myname$$
trap 'rm -f $temp; exit' 0 1 2 15

And change this line inside the while loop, around line 38:

*) $cat "$1" | $prog $opts ;;

to these three lines:

*) $cat "$1" > $temp
   $prog $opts $temp
   ;;

- JP


Previous: 25.4 The "less" Pager: More than "more"UNIX Power ToolsNext: 25.6 What's in That White Space?
25.4 The "less" Pager: More than "more"Book Index25.6 What's in That White Space?

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