Printing Files
Before you print a file on a UNIX system, you may want to reformat it to adjust the margins, highlight some words, and so on. Most files can also be printed without reformatting, but the raw printout may not look quite as nice.
Many versions of UNIX include two powerful text formatters, nroff and troff. (There are also versions called gnroff and groff.) They are much too complex to describe here. Before we cover printing itself, let’s look at a simple formatting program called pr.
pr
The pr command does minor formatting of files on the terminal screen or for a printer. For example, if you have a long list of names in a file, you can format it onscreen into two or more columns.
The syntax is:
pr option(s) filename(s)
pr changes the format of the file only on the screen or on the printed copy; it doesn’t modify the original file. Table 4.2 lists some pr options.
Table 4-2. Some pr Options
|
Option |
Description |
|---|---|
|
-k |
Produces k columns of output. |
|
-d |
Double-spaces the output (not on all pr versions). |
|
-h "header" |
Takes the next item as a report header. |
|
-t |
Eliminates printing of header and top/bottom margins. |
Other options allow you to specify the width of the columns, set the page length, and so on.
Before using pr, here are the contents of a sample file named food:
% cat food
Sweet Tooth
Bangkok Wok
Mandalay
Afghani Cuisine
Isle of Java
Big Apple Deli
Sushi and Sashimi
Tio Pepe's Peppers
.
.
.
Let’s use pr options to make a two-column report with the header “Restaurants.” ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access