man-pages/man1p/paste.1p

301 lines
8.4 KiB
Groff

.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
.TH "PASTE" 1P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\" paste
.SH NAME
paste \- merge corresponding or subsequent lines of files
.SH SYNOPSIS
.LP
\fBpaste\fP \fB[\fP\fB-s\fP\fB][\fP\fB-d\fP \fIlist\fP\fB]\fP \fIfile\fP\fB...\fP
.SH DESCRIPTION
.LP
The \fIpaste\fP utility shall concatenate the corresponding lines
of the given input files, and write the resulting lines to
standard output.
.LP
The default operation of \fIpaste\fP shall concatenate the corresponding
lines of the input files. The <newline> of every
line except the line from the last input file shall be replaced with
a <tab>.
.LP
If an end-of-file condition is detected on one or more input files,
but not all input files, \fIpaste\fP shall behave as though
empty lines were read from the files on which end-of-file was detected,
unless the \fB-s\fP option is specified.
.SH OPTIONS
.LP
The \fIpaste\fP utility shall conform to the Base Definitions volume
of IEEE\ Std\ 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
.LP
The following options shall be supported:
.TP 7
\fB-d\ \fP \fIlist\fP
Unless a backslash character appears in \fIlist\fP, each character
in \fIlist\fP is an element specifying a delimiter
character. If a backslash character appears in \fIlist\fP, the backslash
character and one or more characters following it are an
element specifying a delimiter character as described below. These
elements specify one or more delimiters to use, instead of the
default <tab>, to replace the <newline> of the input lines. The elements
in \fIlist\fP shall be used circularly; that
is, when the list is exhausted the first element from the list is
reused. When the \fB-s\fP option is specified:
.RS
.IP " *" 3
The last <newline> in a file shall not be modified.
.LP
.IP " *" 3
The delimiter shall be reset to the first element of \fIlist\fP after
each \fIfile\fP operand is processed.
.LP
.RE
.LP
When the \fB-s\fP option is not specified:
.RS
.IP " *" 3
The <newline>s in the file specified by the last \fIfile\fP operand
shall not be modified.
.LP
.IP " *" 3
The delimiter shall be reset to the first element of list each time
a line is processed from each file.
.LP
.RE
.LP
If a backslash character appears in \fIlist\fP, it and the character
following it shall be used to represent the following
delimiter characters:
.TP 7
\fB\\n\fP
.RS
<newline>.
.RE
.TP 7
\fB\\t\fP
.RS
<tab>.
.RE
.TP 7
\fB\\\\\fP
.RS
Backslash character.
.RE
.TP 7
\fB\\0\fP
.RS
Empty string (not a null character). If \fB'\\0'\fP is immediately
followed by the character \fB'x'\fP , the character
\fB'X'\fP , or any character defined by the \fILC_CTYPE\fP \fBdigit\fP
keyword (see the Base Definitions volume of
IEEE\ Std\ 1003.1-2001, Chapter 7, Locale), the results are unspecified.
.RE
.sp
.LP
If any other characters follow the backslash, the results are unspecified.
.TP 7
\fB-s\fP
Concatenate all of the lines of each separate input file in command
line order. The <newline> of every line except the
last line in each input file shall be replaced with the <tab>, unless
otherwise specified by the \fB-d\fP option.
.sp
.SH OPERANDS
.LP
The following operand shall be supported:
.TP 7
\fIfile\fP
A pathname of an input file. If \fB'-'\fP is specified for one or
more of the \fIfile\fPs, the standard input shall be
used; the standard input shall be read one line at a time, circularly,
for each instance of \fB'-'\fP . Implementations shall
support pasting of at least 12 \fIfile\fP operands.
.sp
.SH STDIN
.LP
The standard input shall be used only if one or more \fIfile\fP operands
is \fB'-'\fP . See the INPUT FILES section.
.SH INPUT FILES
.LP
The input files shall be text files, except that line lengths shall
be unlimited.
.SH ENVIRONMENT VARIABLES
.LP
The following environment variables shall affect the execution of
\fIpaste\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).
.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
\fINLSPATH\fP
Determine the location of message catalogs for the processing of \fILC_MESSAGES
\&.\fP
.sp
.SH ASYNCHRONOUS EVENTS
.LP
Default.
.SH STDOUT
.LP
Concatenated lines of input files shall be separated by the <tab>
(or other characters under the control of the \fB-d\fP
option) and terminated by a <newline>.
.SH STDERR
.LP
The standard error shall be used only for diagnostic messages.
.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
If one or more input files cannot be opened when the \fB-s\fP option
is not specified, a diagnostic message shall be written to
standard error, but no output is written to standard output. If the
\fB-s\fP option is specified, the \fIpaste\fP utility shall
provide the default behavior described in \fIUtility Description Defaults\fP
\&.
.LP
\fIThe following sections are informative.\fP
.SH APPLICATION USAGE
.LP
When the escape sequences of the \fIlist\fP option-argument are used
in a shell script, they must be quoted; otherwise, the
shell treats the \fB'\\'\fP as a special character.
.LP
Conforming applications should only use the specific backslash escaped
delimiters presented in this volume of
IEEE\ Std\ 1003.1-2001. Historical implementations treat \fB'\\x'\fP
, where \fB'x'\fP is not in this list, as
\fB'x'\fP , but future implementations are free to expand this list
to recognize other common escapes similar to those accepted
by \fIprintf\fP and other standard utilities.
.LP
Most of the standard utilities work on text files. The \fIcut\fP utility
can be used to
turn files with arbitrary line lengths into a set of text files containing
the same data. The \fIpaste\fP utility can be used to
create (or recreate) files with arbitrary line lengths. For example,
if \fIfile\fP contains long lines:
.sp
.RS
.nf
\fBcut -b 1-500 -n file > file1
cut -b 501- -n file > file2
\fP
.fi
.RE
.LP
creates \fBfile1\fP (a text file) with lines no longer than 500 bytes
(plus the <newline>) and \fBfile2\fP that contains
the remainder of the data from \fIfile\fP. Note that \fBfile2\fP is
not a text file if there are lines in \fIfile\fP that are
longer than 500 + {LINE_MAX} bytes. The original file can be recreated
from \fBfile1\fP and \fBfile2\fP using the command:
.sp
.RS
.nf
\fBpaste -d "\\0" file1 file2 > file
\fP
.fi
.RE
.LP
The commands:
.sp
.RS
.nf
\fBpaste -d "\\0" ...
paste -d "" ...
\fP
.fi
.RE
.LP
are not necessarily equivalent; the latter is not specified by this
volume of IEEE\ Std\ 1003.1-2001 and may result in
an error. The construct \fB'\\0'\fP is used to mean "no separator"
because historical versions of \fIpaste\fP did not follow
the syntax guidelines, and the command:
.sp
.RS
.nf
\fBpaste -d"" ...
\fP
.fi
.RE
.LP
could not be handled properly by \fIgetopt\fP().
.SH EXAMPLES
.IP " 1." 4
Write out a directory in four columns:
.sp
.RS
.nf
\fBls | paste - - - -
\fP
.fi
.RE
.LP
.IP " 2." 4
Combine pairs of lines from a file into single lines:
.sp
.RS
.nf
\fBpaste -s -d "\\t\\n" file
\fP
.fi
.RE
.LP
.SH RATIONALE
.LP
None.
.SH FUTURE DIRECTIONS
.LP
None.
.SH SEE ALSO
.LP
\fIUtility Description Defaults\fP , \fIcut\fP , \fIgrep\fP , \fIpr\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 .