pr - print files
pr [+page][-column][-adFmrt][-e[char][gap]][-h header][-i[char][gap]] [-l lines][-n[char][width]][-o offset][-s[char]][-w width][-fp] [file...]
The pr utility is a printing and pagination filter. If 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 that includes the page number, date, time and the pathname of the file
- a 5-line trailer consisting of blank lines.
If standard output is associated with a terminal, diagnostic messages will be deferred until the pr utility has completed processing.
When options specifying multi-column output are specified, output text columns will be of equal width; input lines that do not fit into a text column will be truncated. By default, text columns are separated with at least one blank character.
The pr utility supports the XBD specification, Utility Syntax Guidelines , except that: the page option has a "+" delimiter; page and column can be multi-digit numbers; some of the option-arguments are optional; and some of the option-arguments cannot be specified as separate arguments from the preceding option letter. In particular, the -s option does not allow the option letter to be separated from its argument, and the options -e, -i and -n require that both arguments, if present, not be separated from the option letter.
The following options are supported. In the following option descriptions, column, lines, offset, page and width are positive decimal integers; gap is a non-negative decimal integer.
- Begin output at page number page of the formatted input.
- Produce multi-column output that is arranged in column columns (default is 1) and is written down each column in the order in which the text is received from the input file. This option should not be used with -m. The options -e and -i will be assumed for multiple text-column output. Whether or not text columns are produced with identical vertical lengths is unspecified, but a text column will never exceed the length of the page (see the -l option). When used with -t, use the minimum number of lines to write the output.
- 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).
- Produce output that is double-spaced; append an extra newline character following every newline character found in the input.
- Expand each input tab character 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, it defaults to 8. All tab characters in the input will be expanded into the appropriate number of space characters. If any non-digit character, char, is specified, it will be used as the input tab character.
- Use a form-feed character for new pages, instead of the default behaviour that uses a sequence of newline characters. Pause before beginning the first page if the standard output is associated with a terminal.
- Use a form-feed character for new pages, instead of the default behaviour that uses a sequence of newline characters.
- -h header
- Use the string header to replace the contents of the file operand in the page header.
- In output, replace multiple space characters with tab characters wherever two or more adjacent space characters reach column positions gap+1, 2*gap+1, 3*gap+1, and so on. If gap is zero or is omitted, default tab settings at every eighth column position are assumed. If any non-digit character, char, is specified, it will be 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 will suppress both the header and trailer, as if the -t option were in effect.
- Merge files. Standard output will be formatted so the pr utility writes one line from each file specified by a file operand, side by side into text columns of equal fixed widths, in terms of the number of column positions. Implementations support merging of at least nine file operands.
- Provide width-digit line numbering (default for width is 5). The number will occupy the first width column positions of each text column of default output or each line of -m output. If char (any non-digit character) is given, it will be appended to the line number to separate it from whatever follows (default for char is a tab character).
- -o offset
- Each line of output will be preceded by offset <space>s. If the -o option is not specified, the default offset is zero. The space taken will be in addition to the output line width (see -w option below).
- Pause before beginning each page if the standard output is directed to a terminal (pr will write an alert character to standard error and wait for a carriage-return character to be read on /dev/tty).
- Write no diagnostic reports on failure to open files.
- Separate text columns by the single character char instead of by the appropriate number of space characters (default for char is the tab character).
- Write neither the five-line identifying header nor the five-line trailer usually supplied for each page. Quit writing 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 the -w option is not specified and the -s option is not specified, the default width is 72. If the -w option is not specified and the -s option is specified, the default width is 512. For single column output, input lines will not be truncated.
The following operand is supported:
- A pathname of a file to be written. If no file operands are specified, or if a file operand is "-", the standard input will be used.
The standard input will be used only if no file operands are specified, or if a file operand is "-". See the INPUT FILES section.
The input files must be text files.
The file /dev/tty is used to read responses required by the -p option.
The following environment variables affect the execution of pr:
- Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
- If set to a non-empty string value, override the values of all the other internationalisation variables.
- Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- versus multi-byte characters in arguments and input files) and which characters are defined as printable (character class print). Non-printable characters still will be written to standard output, but are not counted for the purpose for column-width and line-length calculations.
- Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
- Determine the format of the date and time for use in writing header lines.
- Determine the location of message catalogues for the processing of LC_MESSAGES .
- Determine the timezone for use in writing header lines.
If pr receives an interrupt while writing to a terminal, it will flush all accumulated error messages to the screen before terminating.
The pr utility output will be a paginated version of the original file (or files). This pagination will be accomplished using either form-feed characters or a sequence of newline characters, as controlled by the -F or -f option. Page headers will be generated unless the -t option is specified. The page headers will be of the form:
"\n\n%s %s Page %d\n\n\n", <output of date>, <file>, <page number>
In the POSIX locale, the <output of date> field, representing the date and time of last modification of the input file (or the current date and time if the input file is standard input), is equivalent to the output of the following command as it would appear if executed at the given time:without the trailing newline character, if the page being written is from standard input. If the page being written is not from standard input, in the POSIX locale, the same format will be used, but the time used will be the modification time of the file corresponding to file instead of the current time. When the LC_TIME locale category is not set to the POSIX locale, a different format and order of presentation of this field may be used.
date "+%b %e %H:%M %Y"
If the standard input is used instead of a file operand, the <file> field will be replaced by a null string.
If the -h option is specified, the <file> field will be replaced by the header argument.
Used for diagnostic messages and for alerting the terminal when -p is specified.
The following exit values are returned:
- All files were written successfully.
- An error occurred.
- Print a numbered list of all files in the current directory:
ls -a | pr -n -h "Files in $(pwd)."
- Print file1 and file2 as a double-spaced, three-column listing headed by "file list":
pr -3d -h "file list" file1 file2
- Write file1 on file2 , expanding tabs to columns 10, 19, 28, ... :
pr -e9 -t <file1 >file2
It is possible that a new interface that conforms to the Utility Syntax Guidelines will be introduced.