UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 43.6 Printing to a Terminal Printer Chapter 43
Printing
Next: 43.8 Fixing Margins with pr and fold
 

43.7 Quick-and-Dirty Formatting Before Printing

The line printer spooler (43.2) prints what you send it. If you send it a continuous stream of text (and the printer is set up to print text files rather than PostScript), that's just what you'll probably get: no page breaks, indenting, or other formatting features.

That's where pr comes in. It's a simple formatter that breaks its input into "pages" that will fit onto a standard 66-line page. (Well, US standard anyway.) It adds a header that automatically includes the date and time, the file name, and a page number. It also adds a footer that ensures that text doesn't run off the bottom of the page.

This is just what you want if you are sending program source code or other streams of unbroken text to a printer. For that matter, pr is often very handy for sending text to your screen. In addition to its default behavior, it has quite a few useful options:

-f

Separate pages using formfeed character (^L) instead of a series of blank lines.

-hstr

Replace default header with string str. See article 35.17.

-ln

Set page length to n (default is 66).

-m

Merge files, printing one in each column (can't be used with -num and -a). Text is chopped to fit. See article 35.17. This is a poor man's paste (35.18).

-sc

Separate columns with c (default is a tab).

-t

Omit the page header and trailing blank lines.

-wnum

Set line width for output made into columns to num (default is 72).

+num

Begin printing at page num (default is 1).

-n

Produce output having n columns (default is 1). See article 35.17.

There are also options that apply only to the System V version:

-a

Multi-column format; list items in rows going across.

-d

Double-spaced format.

-ecn

Set input tabs to every nth position (default is 8), and use c as field delimiter (default is a tab).

-F

Fold input lines (avoids truncation by -a or -m).

-icn

For output, replace white space with field delimiter c (default is a tab) every nth position (default is 8).

-ncn

Number lines with numbers n digits in length (default is 5), followed by field separator c (default is a tab). See also nl.

-on

Offset each line n spaces (default is 0).

-p

Pause before each page.

-r

Suppress messages for files that can't be found.

Let's put this all together with a couple of examples:

- TOR


Previous: 43.6 Printing to a Terminal Printer UNIX Power ToolsNext: 43.8 Fixing Margins with pr and fold
43.6 Printing to a Terminal Printer Book Index43.8 Fixing Margins with pr and fold

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