Classic Shell Scripting - Arnold Robbins [52]
The newest generation of devices combines printing, copying, and scanning into a single system with a disk filesystem and network access, support for multiple page-description languages and graphics file formats, and, in at least one case, GNU/Linux as the embedded operating system.
Unfortunately, Unix printing software has not adapted rapidly enough to these improvements in printing technology, and command-level support for access to many features of newer printers remains poor. Two notable software projects attempt to remedy this situation: Common UNIX Printing System[3] (CUPS), and lpr next generation[4] (LPRng). Many large Unix sites have adopted one or the other; both provide familiar Unix printing commands, but with a lot more options. Both fully support printing of PostScript and PDF files: when necessary, they use the Aladdin or GNU ghostscript interpreter to convert such files to other formats needed by less-capable printers. CUPS also supports printing of assorted graphics image file formats, and n-up printing to place several reduced page images on a single sheet.
Other Printing Software
Despite its name, the venerable pr command does not print files, but rather, filters data in preparation for printing. In the simplest case, pr produces a page header timestamped with the file's modification time, or if input is from a pipe, with the current time, followed by the filename (empty for piped input) and a page number, with a fixed number (66) of lines per page. The intent was that:
pr file(s) | lp
would print nice listings. However, that simplicity has not worked since the old mechanical printers of the 1970s were retired. Default font sizes and line spacing vary between printers, and multiple paper sizes are in common use.
* * *
pr
Usage
pr [ options ] [ file(s) ]
Purpose
Paginate text files for printing.
Major options
-c n
Produce n-column output. This option can be abbreviated to - n (e.g., -4 instead of -c4).
-f
Prefix each page header after the first with an ASCII formfeed character. This option is called -F on FreeBSD, NetBSD, and Mac OS X. OpenBSD recognizes both options. POSIX has both, but assigns them slightly different meanings.
-h althdr
Use the string althdr to replace the filename in the page header.
-l n
Produce n-line pages. Some implementations include page header and trailer lines in the count, whereas others do not.
-o n
Offset output lines with n spaces.
-t
Suppress page headers.
-w n
Produce lines of at most n characters. For single-column output, wrap longer lines onto additional lines as needed; otherwise, for multicolumn output, truncate long lines to fit.
Behavior
pr reads the specified files, or standard input if no files are given, and writes the paginated data on standard output.
Caveats
pr implementations vary considerably in supported options and output formatting; the GNU coreutils version provides a way to get consistent behavior on all systems.
* * *
Instead, you generally have to experiment with setting the output page length with the -l option, and often the page width with the -w option and a text offset with the -o option. It is also essential to add the -f option (-F on some systems) to output an ASCII formfeed control character at the start of every page header after the first, to guarantee that each header starts a new page. The reality is that you generally have to use something like this:
pr -f -l60 -o10 -w65 file(s) | lp
If you use a different printer later, you may need to change those numeric parameters. This makes it hard to use pr reliably in portable shell scripts.
There is one feature of pr that is often convenient: the -c n option requests n-column output. If you combine that with the -t option to omit the