PR(1P) | POSIX Programmer's Manual | PR(1P) |
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
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 shall be read, formatted, and written to standard output. By default, the input shall be separated into 66-line pages, each with:
If standard output is associated with a terminal, diagnostic messages shall be deferred until the pr utility has completed processing.
When options specifying multi-column output are specified, output text columns shall be of equal width; input lines that do not fit into a text column shall be truncated. By default, text columns shall be separated with at least one <blank>.
The pr utility shall conform to the Base Definitions volume of POSIX.1‐2017, Section 12.2, 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 shall be supported. In the following option descriptions, column, lines, offset, page, and width are positive decimal integers; gap is a non-negative decimal integer.
For single column output, input lines shall not be truncated.
The following operand shall be supported:
The standard input shall be used only if no file operands are specified, or if a file operand is '-'. See the INPUT FILES section.
The input files shall be text files.
The file /dev/tty shall be used to read responses required by the -p option.
The following environment variables shall affect the execution of pr:
If pr receives an interrupt while writing to a terminal, it shall flush all accumulated error messages to the screen before terminating.
The pr utility output shall be a paginated version of the original file (or files). This pagination shall be accomplished using either <form-feed> characters or a sequence of <newline> characters, as controlled by the -F or -f option. Page headers shall be generated unless the -t option is specified. The page headers shall 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), shall be equivalent to the output of the following command as it would appear if executed at the given time:
date "+%b %e %H:%M %Y"
without the trailing <newline>, 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 shall be used, but the time used shall 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.
If the standard input is used instead of a file operand, the <file> field shall be replaced by a null string.
If the -h option is specified, the <file> field shall be replaced by the header argument.
The standard error shall be used for diagnostic messages and for alerting the terminal when -p is specified.
None.
None.
The following exit values shall be returned:
Default.
The following sections are informative.
A conforming application must protect its first operand, if it starts with a <plus-sign>, by preceding it with the "--" argument that denotes the end of the options. For example, pr+x could be interpreted as an invalid page number or a file operand.
ls -a | pr -n -h "Files in $(pwd)."
pr -3d -h "file list" file1 file2
pr -e9 -t <file1 >file2
This utility is one of those that does not follow the Utility Syntax Guidelines because of its historical origins. The standard developers could have added new options that obeyed the guidelines (and marked the old options obsolescent) or devised an entirely new utility; there are examples of both actions in this volume of POSIX.1‐2017. Because of its widespread use by historical applications, the standard developers decided to exempt this version of pr from many of the guidelines.
Implementations are required to accept option-arguments to the -h, -l, -o, and -w options whether presented as part of the same argument or as a separate argument to pr, as suggested by the Utility Syntax Guidelines. The -n and -s options, however, are specified as in historical practice because they are frequently specified without their optional arguments. If a <blank> were allowed before the option-argument in these cases, a file operand could mistakenly be interpreted as an option-argument in historical applications.
The text about the minimum number of lines in multi-column output was included to ensure that a best effort is made in balancing the length of the columns. There are known historical implementations in which, for example, 60-line files are listed by pr -2 as one column of 56 lines and a second of 4. Although this is not a problem when a full page with headers and trailers is produced, it would be relatively useless when used with -t.
Historical implementations of the pr utility have differed in the action taken for the -f option. BSD uses it as described here for the -F option; System V uses it to change trailing <newline> characters on each page to a <form-feed> and, if standard output is a TTY device, sends an <alert> to standard error and reads a line from /dev/tty before the first page. There were strong arguments from both sides of this issue concerning historical practice and as a result the -F option was added. XSI-conformant systems support the System V historical actions for the -f option.
The <output of date> field in the -l format is specified only for the POSIX locale. As noted, the format can be different in other locales. No mechanism for defining this is present in this volume of POSIX.1‐2017, as the appropriate vehicle is a message catalog; that is, the format should be specified as a ``message''.
None.
expand, lp
The Base Definitions volume of POSIX.1‐2017, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
2017 | IEEE/The Open Group |