pr - Format a file in paginated form and send it to standard output

Format

pr [-adFfprtW] [-n | -c n | -m] [-e [char][gap]] [-H header-fmt] [-h header] [-i[char] . [gap]] [-l n] [-n[char] [n]] [-o n] [-s[char]] [-w n] [+n] [file ...]

Description

pr prints the specified files on standard output (stdout) in a paginated form. If you do not specify any files or if you specify a file name of -, pr reads the standard input. By default, pr formats the given files into single-column 66-line pages. Each page has a five-line header. By default, the third line contains the file's path name, the date it was last modified, and the current page number; the other lines are blank. A five-line trailer consists of blank lines.

If you specify multiple columns, pr places its output in columns of equal width separated by at least one space, truncating each line to fit in its column. Input lines can be ordered down the columns or across the page on output; or different columns can each represent different files.

Options

+n
Starts printing with the nth page of each file; that is, skips the first n-1 pages. The default for n is 1.
-n
Prints n columns of output. When you specify this option, pr behaves as though you had also specified the -e and -i options. When you specify both this option and -t, pr uses the minimum number of lines possible to display the output. Do not specify this option with the -m option.
-a
Orders input lines across the page on output, instead of down. You should use this option only with -n.
-c n
Displays n columns of output. When you specify this option, pr behaves as though you had also specified the -e and -i options. When you specify both this option and -t, pr uses the minimum number of lines possible to display the output. Do not specify this option with -m.
-d
Produces double-spaced output.
-e[char][gap]
Expands each occurrence of the input tab character to a string of spaces so that the following character has the next column position which is a positive multiple of gap, plus 1. If you do not specify gap, or if it is zero, pr assumes that gap has the value of 8. If you specify the nondigit character char, pr treats it as the input tab character. Otherwise, pr uses the standard tab character.
-F
Uses form feeds to separate pages. pr normally separates pages by sending a series of <newline> characters to fill the length of a page.
-f
Uses form feeds to separate pages. When output is to a terminal, pr sounds the bell and waits for you to type a carriage return before displaying the text. pr normally separates pages by sending a series of <newline> characters to fill the length of a page.
-H header_fmt
Lets you customize your header line by specifying a format with the string header_fmt. pr recognizes the following special formatting commands:
%c
Date and time
%F
The current file name , or header string given by -h
%P
Page number
%L
Line number
%D
Date
%T
Time
%u
The current user name

The default header format is equivalent to the option: -H "%c %F Page %P"

-h header
Uses the header string instead of the file name on each succeeding page header.
-i[char][gap]
Replaces white space with tabs on output. char, if given, is the output tab character. The default is the tab character. pr sets tabs every gap positions; the default for gap is 8. If this tab character differs from the input tab character and the actual data contains this tab character, the result is liable to be quite a mess.
-l n
Sets the number of lines per page of output. The default is 66. The actual number of lines printed per page is this number less 5 for the header and 5 for the trailer. If n is less than 10 (the number of lines needed for the header and the trailer), pr displays neither the header nor the trailer.
-m
Prints each file in its own column down the page. This overrides the -a option, forcing the -n option to be the number of files given. When you also specify the -n option, it gives line numbers for the first column only.
-n[char][n]
Numbers the lines of each file. Each number takes up n positions; the default for n is 5. The character char separates the number from the line; this defaults to the tab character. If char is the same as the input tab character, pr follows the number with the spaces needed to get to the next tab stop. pr may in turn replace these spaces with the output tab character if you specified the -i option. For multicolumn output, pr adds line numbers to each column. The -m option gives the line number for the first column only.
-o n
Offsets each line of output by n character positions.
-p
Pauses before the beginning of each page if output is to a terminal device. pr sounds the bell and waits for a carriage return from the controlling workstation (not the input files).
-r
Suppresses error messages due to failures when opening files.
-s[char]
Prints each column at its correct length. The character char separates columns. The default value for char is the tab character. This character is never replaced by the output tab character. Normally pr pads each column with spaces or truncates it to the exact column width. Unless the -w option is also used, -s resets the page width to 512 column positions.
-t
Does not print the headers and trailers, and quits after the last line of the file. It does not display any extra lines.
-W
Folds lines at the column width when you do not specify the -s option; pr treats each separate part of the line as a separate line.
-w n
Sets the width of the page to n column positions. If you do not specify this option, the default page width is 72 (if you did not specify the -s option) or 512 (if you did specify -s). This page width does not normally apply to single-column output; however, single-column output with the -W option does use this width.

Files

pr uses the following file:
/dev/tty
For prompting.

Environment variables

pr uses the following environment variable:
TZ
Contains the local time zone. pr uses this value when displaying times in header lines.

Localization

pr uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_CTYPE
  • LC_MESSAGES
  • LC_TIME
  • NLSPATH

Exit values

0
Successful completion
1
Failure due to any of the following:
  • Insufficient memory
  • Insufficient line width
  • Write error on stdout
2
Syntax error or unknown command-line option

Messages

Possible error messages include:
Missing header
You specified -h or -H but did not supply a header or header_fmt string.
Width is insufficient
The line is not wide enough to hold the given number of columns with the given column width; or a column is not wide enough to hold the minimum amount of data.

Portability

POSIX.2, X/Open Portability Guide.

The -c, -H, -p, and -W options are extensions of the POSIX standard.

In a double-byte environment, remember that column positions are always based on the width of characters. A double-byte character may take up two columns of output (called a thick character), but a single-byte character will only take up one column of output (called a thin character). Specify column widths according to the expected thickness of characters.

For example, with a column width of 10, then ten thin characters or five thick characters are displayed.

Related information

cat, expand, fold, unexpand

For information about setting the local time zone, see TZ environment variable.