pr - Print files

Synopsis

pr [+page] [-column] [-adFmrt] [-e [char][gap]] [-h header] [-i[char][gap]] [-l line] [-n[char][width]] [-o offset] [-s[char]] [-w width] [-] [file ...]

Description

The pr utility is a printing and pagination filter for text files. When multiple input files are specified, each is read, formatted, and written to standard output. By default, the input is separated into 66-line pages, each with a 5-line header with the page number, date, time, and the path name of the file and a 5-line trailer consisting of blank lines. If the LC_TIME environment variable is set, the date and time in the header is formatted using the format specified by the d_t_fmt keyword in the LC_TIME category of the specified locale.

When multiple column output is specified, text columns are of equal width. By default text columns are separated by at least one <space>. Input lines that do not fit into a text column are truncated. Lines are not truncated under single column output.

Error messages are written to standard error during the printing process (if output is redirected) or after all successful file printing is complete (when printing to a terminal).

If pr receives an interrupt while printing to a terminal, it flushes all accumulated error messages to the screen before terminating.

Options

Notes:

  1. In the following option descriptions, column, lines, offset, page, and width are positive decimal integers and gap is a nonnegative decimal integer.
  2. The -s option does not allow the option letter to be separated from its argument.
  3. The -e, -i, and -n options require that both arguments, if present, not be separated from the option letter.
+page
Begin output at page number page of the formatted input.
-column
Produce output that is columns wide (default is 1) that is written vertically down each column in the order in which the text is received from the input file. The options -e and -i are assumed. This option should not be used with the -m option. When used with the -t option the minimum number of lines is used to display the output.
-a
Modify the effect of the column option so that the columns are filled across the page in a round-robin order (for example, when column is 2, the first input line heads column 1, the second heads column 2, the third is the second line in column 1, and so on). This option requires the use of the column option.
-d
Produce output that is double spaced. An extra <newline> character is output following every <newline> found in the input.
-e [char][gap]
Expand each input <tab> to the next greater column position specified by the formula n*gap+1, where n is an integer > 0. If gap is zero or is omitted the default is 8. All <tab> characters in the input are expanded into the appropriate number of <space>s . If any nondigit character, char, is specified, it is used as the input tab character.
-F
Use a <form-feed> character for new pages, instead of the default behavior that uses a sequence of <newline> characters.
-h header
Use the string header to replace the file name in the header line.
-i [char][gap]
In output, replace multiple <space>s with <tab>s whenever two or more adjacent <space>s reach column positions gap+1, 2*gap+1, and so on. If gap is zero or omitted, default <tab> settings at every eighth column position is used. If any nondigit character, char, is specified, it is used as the output <tab> character.
-l lines
Override the 66 line default and reset the page length to lines. If lines is not greater than the sum of both the header and trailer depths (in lines), the pr utility suppresses output of both the header and trailer, as if the -t option were in effect.
-m
Merge the contents of multiple files. One line from each file specified by a file operand is written side by side into text columns of equal fixed widths, in terms of the number of column positions. The number of text columns depends on the number of file operands successfully opened. The maximum number of files merged depends on page width and the per process open file limit. The options -e and i are assumed.
-n [char][width]
Provide width digit line numbering. The default for width, if not specified, is 5. The number occupies the first width column positions of each text column or each line of -m output. If char (any nondigit character) is given, it is appended to the line number to separate it from whatever follows. The default for char is a <tab>. Line numbers longer than width columns are truncated.
-o offset
Each line of output is preceded by offset <spaces>s. If this option is not specified, the default is zero. The space taken is in addition to the output line width.
-r
Write no diagnostic reports on failure to open a file.
-s char
Separate text columns by the single character char instead of by the appropriate number of <space>s (default for char is the <tab> character).
-t
Print neither the five-line identifying header nor the five-line trailer typically supplied for each page. Quit printing after the last line of each file without spacing to the end of the page.
-w width
Set the width of the line to width column positions for multiple text-column output only. If this option is not specified and the -s option is not specified, the default width is 72. If this option is not specified and the -s option is specified, the default width is 512.

Operands

Each file is a path name of a file to be printed. If no file operands are specified, or if a file operand is -, the standard input is used.

Environment Variables

pr is affected by the following environment variables:

LANG
Provides a default value for locale categories that are not specifically set with a variable starting with LC_.
LC_TIME
Defines the format of the date and time used in writing header lines.

Exit Status

Related information

Examples

  1. Print a file starting at page 3:
    pr +3 source.java
    
  2. Print every *.java file and change the header message:
    pr -h 'JDK source files and examples' code/*.java