Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

pr - prepare files for printing

&pagelevel(4)&pagelevel

The pr command formats and writes the contents of files on the standard output.

Output is either in single columns (default) or in multiple columns. Multi-column output can be produced by using either the - option or the -m option.


Syntax


pr[ option][ file]...

No option specified

The files are divided into pages which are separated by a sequence of line feed characters. The page length is 66 lines, which includes 10 lines of header and trailer output.

Headers are made up of two blank lines, one line of text containing the page number, date and time that the file was last modified, and the file name, and two more blank lines. Trailers consist of five blank lines.

Files are output in single columns. Overlong lines are split.

If the standard output is associated with a terminal, error messages are not reported until all the specified files have been output.

Option overview

The following overview indicates the various options you can use to modify the output format:

+Set first page to be displayed
-Split text into columns
-aDefine how columns are to be filled
-wDefine page width for multi-column output
-sPrevent truncation of lines in columns
-mOutput files simultaneously in columns
-dDouble-space the output
-eConvert tabs to spaces
-iConvert spaces to tabs
-nNumber lines
-oIndent text
-lChange page length
-hChange file name in header
-pDisplay file one page at a time

-f

Use form-feed characters to separate pages
-FUse form-feed characters to separate pages
-rSuppress error messages
-tSuppress output of header and trailer

Description of options in alphabetical order

+page_number

Starts output at the specified page_number.

+ not specified: Output begins at the first page.

-columns

Outputs the file in columns columns. Output appears as if -e and -i have been set with their default values.

This option cannot be combined with -m.

The columns of a page are filled with input lines from top to bottom. This setting can be changed with -a.

The default page width for multi-column output is 72. This setting can be changed with -w.

pr determines the width of each column by dividing the page width by the number of columns. If a line is too long, it is truncated to the right. Truncation can be suppressed with -s.

- not specified:
Single-column output.

-a

(a - across)

Arranges multi-column output across the page.

The number of columns must be greater than 1. This number can be defined with -columns or -w.

If a line is too long to fit in a column, it is truncated to the right. Truncation can be suppressed with -s.

The -a option cannot be combined with the -m option.

-a not specified:
pr fills columns down the page from top to bottom.

-d

(d - double-space)

Double-spaces the output. Blank lines that result from double-spacing are deleted when they occur at the top of a page.

-e[tab_char][spacing]

Replaces each tab character in the input by an appropriate number of spaces.

tab_char

Character which pr interprets as a tab character. May be any non-numeric character.

tab_char not specified:
pr uses the horizontal tab character (see section “ASCII character set (ISO 646)”).

spacing

Spacing between tabs. The first tab stop in a line is always set in column 1. If spacing is 0, the default value of 8 characters is assumed.

spacing not specified:
The tab spacing is 8 characters.

-f

(f - form feed)

Uses a single form-feed character to separate output pages.

If the output is to a terminal, pr pauses before the first page and sounds the terminal bell. You then start the output by pressing the enter key.

-f not specified:
Pages are separated by a sequence of line feed characters.

-F  

(F - form feed)

Pages are separated by a single form feed character.

-F not specified:
Pages are separated by a sequence of line feed characters.

Caution:
In previous versions, the -F option had a different meaning. This is now supported by pr by default.

-h header

Writes a text of your choice in the header instead of the file name. This option is ignored if you also specify -t or -l with a page length of 10 or less.

-i[tab_char][spacing]

Replaces white space in the input text with the tab character tabchar at appropriate positions in the output text.

tab_char

Character which pr interprets as a tab character. May be any non-numeric character.

tab_char not specified:
pr uses the horizontal tab character (see section “ASCII character set (ISO 646)”).

spacing

Spacing between tabs. The first tab stop in a line is always set in column 1. If spacing is 0, the default value of 8 characters is assumed.

spacing not specified:
The tab spacing is 8 characters.

-l length

Sets the length of an output page.

The page length includes a total of 10 lines for the header and footer. Consequently, if you specify a value of 10 or less for length, the header and trailer will not be output (see the -t option).

-l not specified:
Each page is made up of 66 lines.

-m

Merges and outputs all named files simultaneously, one column per file. The maximum number of files that may be specified is nine.

-m cannot be used together with -columns. Otherwise, the same rules apply as for -columns.

The -m option cannot be combined with the -a option.

-m not specified:
pr outputs files one after the other.

-n[separator][char_pos]

Numbers the lines. For multi-column output, the lines of each individual column are numbered. The line number occupies the first char_pos+1 character positions of each line or each column line.

separator

Character used to separate the line number from the start of the line. May be any non-numeric character.

separator not specified:
A horizontal tab is used as the separator (see section “ASCII character set (ISO 646)”).

char_pos

Number of character positions occupied by line numbers.

char_pos not specified:
Defaults to 5.

-o offset

Offsets (indents) each output line by offset character positions.

-p

If the output is directed to a terminal, pr sounds the terminal bell and pauses before beginning each page. The page is displayed after you press the enter key.

-r

Suppresses diagnostic reports if pr is unable to open a file.

-r not specified:
After completing the entire output, pr issues an error message to report files that could not be accessed.

-s[separator]

Separates columns by the single character separator instead of a tab. If you do not specify -w at the same time, -s also prevents the truncation of overlength lines (up to 512 character) on multi-column output.

separator: Character used to separate columns.

separator not specified:
The default separator is a horizontal tab (see section “ASCII character set (ISO 646)”).

-t

Suppresses the headers and trailers. Terminates printing after the last line of each file instead of padding with spaces to the end of the page.

-w width

Sets the page width for multi-column output. Multi-column output can be produced with -columns or -m.

width: Number of characters in a line.

-w not specified:
The default page width for multi-column output is 72 characters.

file

Name of the file to be prepared for printing. You may specify more than one file. If more than one file is specified, pr outputs them in succession. If you use a dash as the name for file, pr reads from standard input.

If you use the -m option for multi-column output, no more than 9 files may be specified.

file not specified:
pr reads from standard input.

File

/dev/tty*
/dev/term/tty*

Special files for individual terminals.

If standard output is directed to one of the special files /dev/tty*, other output directed to this terminal is delayed until standard output is completed. This prevents error messages from being interspersed throughout the output.

Variable

TZ

Determine the timezone for use in writing header lines.

Locale

The following environment variables affect the execution of pr:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

LC_ALL

If set to a non-empty string value, override the values of all the other internationalization variables.

LC_CTYPE

Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files) and which characters are defined as printable. Non-printable characters still will be written to standard output, but are not counted for the purpose for column-width and line-length calculations.

LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.

LC_TIME

Determine the format of date and time for use in writing header lines.

NLSPATH

Determine the location of message catalogs for the processing of LC_MESSAGES.

Example 1

Print file1 and file2 sequentially in three-column format (-3) using the form-feed character (-f) at the end of each page so as to ensure that the output is independent of the printer type.


$ pr -3f file1 file2 | lp

Example 2

The tab spacing of 8 positions in file1 is to be changed to 6 in file2. First you convert tabs in file1 to spaces (-e; tab spacing = 8), then you reconvert the spaces back to tabs (-i6; tab spacing = 6), and then you write the result to file2. The -t option suppresses the header and trailer for both pr commands.

$ pr -et file1 | pr -i6t > file2

Example 3

The file months contains the name of a month in each line. This file is now to be displayed with pr in three columns (-3) with two-digit numbering (-n2). The columns are to be filled from left to right (-a):

$ pr -3n2a months
Jan 27 16:21 2009 months Page 1
 1      January          5      May              9      September
 2      February         6      June            10      October
 3      March            7      July            11      November
 4      April            8      August          12      December

See also

cat, fold, more