Prettying Up Your Printouts
If you send a file full of plain text to a printer, the result can look ugly: no margins, titles, or anything else. You can use the pr command to make your file look nicer. Use it only with plain text files, however, not with files full of PostScript code, document files from your favorite word processor, or a desktop publishing program.
Titles and page numbers look so official
The simplest thing you can do with the pr command is to add titles and page numbers to your printout. By default, the title is the name of the file and the date and time it was last changed. You can use a pipe (defined in Chapter 7 as the vertical bar, |) to format with pr and print on a single line:
pr myfile | lpr
(Remember to use the lp command rather than lpr , if appropriate.) This command tells the pr program to pretty up the file and pass the results to the lpr program.You can set your own heading by using the -h option with the pr command:
pr -h "My Deepest Thoughts" myfile | lpr
The pr command assumes that printer pages are 66 lines long. If that’s not true for you, rather than the title’s appearing at the top of every page, it sort of oozes down from page to page. You can override the length of the standard page with the -l option. Suppose that the page length is 60 lines. You type this line:
pr -l 60 myfile | lpr
If you want to use pr and not have any heading at the top of the page, use the -t option:
pr -t myfile | lpr
(This example doesn’t do anything interesting to myfile . In the next section, however, you see that it really is useful when you combine it with the margins and stuff.)
Marginally yours
You may frequently put printouts in three-ring binders. Normally, because printing starts very close to the left side of the page, the hole punch may put holes in your text and make the page difficult to read — not to mention make it look stupid. The -o option (that’s a lowercase letter o, not a zero, for offset) pushes the stuff you print to the right, leaving a left margin. To leave five spaces for a left margin, for example, type this command:
pr -o5 myfile | lpr
Sometimes leaving a wider margin at the bottom of the page is nice. You can do that by combining the -l option (to set the page length, as described in the preceding section) with the -f option that tells pr to use a special form-feed character to make the printer start a new page. (Normally, the -l option uses blank lines to space to the next page, like a typewriter.) Use the following command if you’re in this situation:
pr -o5 -l 50 -f myfile | lpr
This command tells UNIX to print just 50 lines per page, indented five spaces. That amount of space in the margin should be enough for anyone.
Seeing double
The -d option tells pr to double-space the printout. Type this command:
pr -d myfile | lpr
This command also puts a title on every page. Use -d -t to avoid that:
pr -d -t myfile | lpr
One column can’t contain me
If the lines in your file are short, you can save paper by printing the file in multiple columns. To print your file in two columns, for example, type
pr -2 myfile | lpr
Astute readers probably can guess what the options -3 , -4 , and up to -9 do. (If you’re not feeling that astute today, these options specify the number of columns you want.) Columns normally run down and then across the page, as they do in newspapers. If your file contains a list of items, one per line, and you want to print them in columns, you may want to change the order in which the lines print. If you want to print items across the page and then move down to the next line, and so on (which is nowhere near as cool), use the -a option in addition to the -2 or -3 option.For a truly baffling effect, you can arrange to print several files side by side with the -m option:
pr -m firstfile secondfile | lpr
This command prints the first line of every file on the first line of the printout, the second line of every file on the second line, and so on. You can specify as many as nine filenames and have them print side by side in skinny little columns. We never have been able to figure out much of a use for this option, although it is definitely a way to produce odd printouts.