.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved 
.TH "PR" 1P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\" pr 
.SH PROLOG
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.
.SH NAME
pr \- print files
.SH SYNOPSIS
.LP
\fBpr\fP
\fB[\fP\fB+\fP\fIpage\fP\fB][\fP\fB-\fP\fIcolumn\fP\fB][\fP\fB-adFmrt\fP\fB][\fP\fB-e\fP\fB[\fP\fIchar\fP\fB][\fP\fI
gap\fP\fB]][\fP\fB-h\fP \fIheader\fP\fB][\fP\fB-i\fP\fB[\fP\fIchar\fP\fB][\fP\fIgap\fP\fB]]
.sp
\fP \fB\ \ \ \ \ \ \fP \fB[\fP\fB-l\fP
\fIlines\fP\fB][\fP\fB-n\fP\fB[\fP\fIchar\fP\fB][\fP\fIwidth\fP\fB]][\fP\fB-o\fP
\fIoffset\fP\fB][\fP\fB-s\fP\fB[\fP\fIchar\fP\fB]][\fP\fB-w\fP \fIwidth\fP\fB][\fP\fB-fp\fP\fB]
.br
\fP \fB\ \ \ \ \ \ \fP \fB[\fP\fIfile\fP\fB...\fP\fB]\fP
.SH DESCRIPTION
.LP
The \fIpr\fP 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:
.IP " *" 3
A 5-line header that includes the page number, date, time, and the
pathname of the file
.LP
.IP " *" 3
A 5-line trailer consisting of blank lines
.LP
.LP
If standard output is associated with a terminal, diagnostic messages
shall be deferred until the \fIpr\fP utility has
completed processing.
.LP
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>.
.SH OPTIONS
.LP
The \fIpr\fP utility shall conform to the Base Definitions volume
of IEEE\ Std\ 1003.1-2001, Section 12.2, Utility Syntax Guidelines,
except that: the \fIpage\fP option has a
\fB'+'\fP delimiter; \fIpage\fP and \fIcolumn\fP 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
\fB-s\fP option does not allow the option letter to be separated from
its argument, and the options \fB-e\fP, \fB-i\fP, and
\fB-n\fP require that both arguments, if present, not be separated
from the option letter.
.LP
The following options shall be supported. In the following option
descriptions, \fIcolumn\fP, \fIlines\fP, \fIoffset\fP,
\fIpage\fP, and \fIwidth\fP are positive decimal integers; \fIgap\fP
is a non-negative decimal integer.
.TP 7
\fB+\fP\fIpage\fP
Begin output at page number \fIpage\fP of the formatted input.
.TP 7
\fB-\fP\fIcolumn\fP
Produce multi-column output that is arranged in \fIcolumn\fP columns
(the default shall be 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 \fB-m\fP. The options
\fB-e\fP and \fB-i\fP shall be assumed for multiple text-column output.
Whether or not text columns are produced with identical
vertical lengths is unspecified, but a text column shall never exceed
the length of the page (see the \fB-l\fP option). When used
with \fB-t\fP, use the minimum number of lines to write the output.
.TP 7
\fB-a\fP
Modify the effect of the \fB-\fP \fIcolumn\fP option so that the columns
are filled across the page in a round-robin order
(for example, when \fIcolumn\fP 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).
.TP 7
\fB-d\fP
Produce output that is double-spaced; append an extra <newline> following
every <newline> found in the input.
.TP 7
\fB-e[\fP\fIchar\fP\fB][\fP\fIgap\fP\fB]\fP
.sp
Expand each input <tab> to the next greater column position specified
by the formula \fIn\fP* \fIgap\fP+1, where \fIn\fP
is an integer > 0. If \fIgap\fP is zero or is omitted, it shall default
to 8. All <tab>s in the input shall be expanded
into the appropriate number of <space>s. If any non-digit character,
\fIchar\fP, is specified, it shall be used as the input
<tab>.
.TP 7
\fB-f\fP
Use a <form-feed> for new pages, instead of the default behavior that
uses a sequence of <newline>s. Pause before
beginning the first page if the standard output is associated with
a terminal. 
.TP 7
\fB-F\fP
Use a <form-feed> for new pages, instead of the default behavior that
uses a sequence of <newline>s.
.TP 7
\fB-h\ \fP \fIheader\fP
Use the string \fIheader\fP to replace the contents of the \fIfile\fP
operand in the page header.
.TP 7
\fB-i[\fP\fIchar\fP\fB][\fP\fIgap\fP\fB]\fP
In output, replace multiple <space>s with <tab>s wherever two or more
adjacent <space>s reach column
positions \fIgap\fP+1, 2* \fIgap\fP+1, 3* \fIgap\fP+1, and so on.
If \fIgap\fP is zero or is omitted, default tab settings at
every eighth column position shall be assumed. If any non-digit character,
\fIchar\fP, is specified, it shall be used as the
output <tab>.
.TP 7
\fB-l\ \fP \fIlines\fP
Override the 66-line default and reset the page length to \fIlines\fP.
If \fIlines\fP is not greater than the sum of both the
header and trailer depths (in lines), the \fIpr\fP utility shall suppress
both the header and trailer, as if the \fB-t\fP option
were in effect.
.TP 7
\fB-m\fP
Merge files. Standard output shall be formatted so the \fIpr\fP utility
writes one line from each file specified by a
\fIfile\fP operand, side by side into text columns of equal fixed
widths, in terms of the number of column positions.
Implementations shall support merging of at least nine \fIfile\fP
operands.
.TP 7
\fB-n[\fP\fIchar\fP\fB][\fP\fIwidth\fP\fB]\fP
.sp
Provide \fIwidth\fP-digit line numbering (default for \fIwidth\fP
shall be 5). The number shall occupy the first \fIwidth\fP
column positions of each text column of default output or each line
of \fB-m\fP output. If \fIchar\fP (any non-digit character)
is given, it shall be appended to the line number to separate it from
whatever follows (default for \fIchar\fP is a
<tab>).
.TP 7
\fB-o\ \fP \fIoffset\fP
Each line of output shall be preceded by offset <space>s. If the \fB-o\fP
option is not specified, the default offset
shall be zero. The space taken is in addition to the output line width
(see the \fB-w\fP option below).
.TP 7
\fB-p\fP
Pause before beginning each page if the standard output is directed
to a terminal ( \fIpr\fP shall write an <alert> to
standard error and wait for a <carriage-return> to be read on \fB/dev/tty\fP).
.TP 7
\fB-r\fP
Write no diagnostic reports on failure to open files.
.TP 7
\fB-s[\fP\fIchar\fP\fB]\fP
Separate text columns by the single character \fIchar\fP instead of
by the appropriate number of <space>s (default for
\fIchar\fP shall be <tab>).
.TP 7
\fB-t\fP
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.
.TP 7
\fB-w\ \fP \fIwidth\fP
Set the width of the line to \fIwidth\fP column positions for multiple
text-column output only. If the \fB-w\fP option is not
specified and the \fB-s\fP option is not specified, the default width
shall be 72. If the \fB-w\fP option is not specified and
the \fB-s\fP option is specified, the default width shall be 512.
.LP
For single column output, input lines shall not be truncated.
.sp
.SH OPERANDS
.LP
The following operand shall be supported:
.TP 7
\fIfile\fP
A pathname of a file to be written. If no \fIfile\fP operands are
specified, or if a \fIfile\fP operand is \fB'-'\fP, the
standard input shall be used.
.sp
.SH STDIN
.LP
The standard input shall be used only if no \fIfile\fP operands are
specified, or if a \fIfile\fP operand is \fB'-'\fP .
See the INPUT FILES section.
.SH INPUT FILES
.LP
The input files shall be text files.
.LP
The file \fB/dev/tty\fP shall be used to read responses required by
the \fB-p\fP option.
.SH ENVIRONMENT VARIABLES
.LP
The following environment variables shall affect the execution of
\fIpr\fP:
.TP 7
\fILANG\fP
Provide a default value for the internationalization variables that
are unset or null. (See the Base Definitions volume of
IEEE\ Std\ 1003.1-2001, Section 8.2, Internationalization Variables
for
the precedence of internationalization variables used to determine
the values of locale categories.)
.TP 7
\fILC_ALL\fP
If set to a non-empty string value, override the values of all the
other internationalization variables.
.TP 7
\fILC_CTYPE\fP
Determine the locale for the interpretation of sequences of bytes
of text data as characters (for example, single-byte as
opposed to multi-byte characters in arguments and input files) and
which characters are defined as printable (character class
\fBprint\fP). Non-printable characters are still written to standard
output, but are not counted for the purpose for column-width
and line-length calculations.
.TP 7
\fILC_MESSAGES\fP
Determine the locale that should be used to affect the format and
contents of diagnostic messages written to standard
error.
.TP 7
\fILC_TIME\fP
Determine the format of the date and time for use in writing header
lines.
.TP 7
\fINLSPATH\fP
Determine the location of message catalogs for the processing of \fILC_MESSAGES
\&.\fP 
.TP 7
\fITZ\fP
Determine the timezone used to calculate date and time strings written
in header lines. If \fITZ\fP is unset or null, an
unspecified default timezone shall be used.
.sp
.SH ASYNCHRONOUS EVENTS
.LP
If \fIpr\fP receives an interrupt while writing to a terminal, it
shall flush all accumulated error messages to the screen
before terminating.
.SH STDOUT
.LP
The \fIpr\fP utility output shall be a paginated version of the original
file (or files). This pagination shall be accomplished
using either <form-feed>s or a sequence of <newline>s, as controlled
by the \fB-F\fP  or \fB-f\fP
option. Page headers shall be generated unless the \fB-t\fP option
is specified. The page headers shall be of the form:
.sp
.RS
.nf

\fB"\\n\\n%s %s Page %d\\n\\n\\n", <\fP\fIoutput of date\fP\fB>, <\fP\fIfile\fP\fB>, <\fP\fIpage number\fP\fB>
\fP
.fi
.RE
.LP
In the POSIX locale, the <\fIoutput\ of\ date\fP> 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:
.sp
.RS
.nf

\fBdate "+%b %e %H:%M %Y"
\fP
.fi
.RE
.LP
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 \fIfile\fP instead of the current time. When the
\fILC_TIME\fP locale category is not set to the POSIX locale, a
different format and order of presentation of this field may be used.
.LP
If the standard input is used instead of a \fIfile\fP operand, the
<\fIfile\fP> field shall be replaced by a null
string.
.LP
If the \fB-h\fP option is specified, the <\fIfile\fP> field shall
be replaced by the \fIheader\fP argument.
.SH STDERR
.LP
The standard error shall be used for diagnostic messages and for alerting
the terminal when \fB-p\fP is specified.
.SH OUTPUT FILES
.LP
None.
.SH EXTENDED DESCRIPTION
.LP
None.
.SH EXIT STATUS
.LP
The following exit values shall be returned:
.TP 7
\ 0
Successful completion.
.TP 7
>0
An error occurred.
.sp
.SH CONSEQUENCES OF ERRORS
.LP
Default.
.LP
\fIThe following sections are informative.\fP
.SH APPLICATION USAGE
.LP
None.
.SH EXAMPLES
.IP " 1." 4
Print a numbered list of all files in the current directory:
.sp
.RS
.nf

\fBls -a | pr -n -h "Files in $(pwd)."
\fP
.fi
.RE
.LP
.IP " 2." 4
Print \fBfile1\fP and \fBfile2\fP as a double-spaced, three-column
listing headed by "file list'':
.sp
.RS
.nf

\fBpr -3d -h "file list" file1 file2
\fP
.fi
.RE
.LP
.IP " 3." 4
Write \fBfile1\fP on \fBfile2\fP, expanding tabs to columns 10, 19,
28, ...:
.sp
.RS
.nf

\fBpr -e9 -t <file1 >file2
\fP
.fi
.RE
.LP
.SH RATIONALE
.LP
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
IEEE\ Std\ 1003.1-2001. Because of its widespread use by
historical applications, the standard developers decided to exempt
this version of \fIpr\fP from many of the guidelines.
.LP
Implementations are required to accept option-arguments to the \fB-h\fP,
\fB-l\fP, \fB-o\fP, and \fB-w\fP options whether
presented as part of the same argument or as a separate argument to
\fIpr\fP, as suggested by the Utility Syntax Guidelines. The
\fB-n\fP and \fB-s\fP 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 \fIfile\fP operand could
mistakenly be interpreted as an option-argument in historical applications.
.LP
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 \fIpr\fP
-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 \fB-t\fP.
.LP
Historical implementations of the \fIpr\fP utility have differed in
the action taken for the \fB-f\fP option. BSD uses it as
described here for the \fB-F\fP option; System V uses it to change
trailing <newline>s 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 \fB/dev/tty\fP before the
first page. There were strong arguments from both sides of this issue
concerning historical practice and as a result the \fB-F\fP
option was added. XSI-conformant systems support the System V historical
actions for the \fB-f\fP option.
.LP
The <\fIoutput\ of\ date\fP> field in the \fB-l\fP 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
IEEE\ Std\ 1003.1-2001, as the appropriate vehicle is a message catalog;
that is, the format should be specified as a
"message".
.SH FUTURE DIRECTIONS
.LP
None.
.SH SEE ALSO
.LP
\fIexpand\fP, \fIlp\fP
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 6, Copyright (C) 2001-2003 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 .
