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 overviewThe following overview indicates the various options you can use to modify the output format:
Description of options in alphabetical order
Starts output at the specified page_number. + not specified: Output begins at the first page.
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:
(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:
(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.
Replaces each tab character in the input by an appropriate number of spaces.
Character which pr interprets as a tab character. May be any non-numeric character. tab_char not specified:
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:
(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:
(F - form feed) Pages are separated by a single form feed character. -F not specified: Caution:
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.
Replaces white space in the input text with the tab character tabchar at appropriate positions in the output text.
Character which pr interprets as a tab character. May be any non-numeric character. tab_char not specified:
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:
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:
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:
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.
Character used to separate the line number from the start of the line. May be any non-numeric character. separator not specified:
Number of character positions occupied by line numbers. char_pos not specified:
Offsets (indents) each output line by offset character positions.
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.
Suppresses diagnostic reports if pr is unable to open a file. -r not specified:
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:
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.
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:
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: |
File
/dev/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.
|
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.
|
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):
|
See also
cat, fold, more |