The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

paste - merge corresponding or subsequent lines of files

 SYNOPSIS



paste [-s][-d list] file...

 DESCRIPTION

The paste utility will concatenate the corresponding lines of the given input files, and write the resulting lines to standard output.

The default operation of paste will concatenate the corresponding lines of the input files. The newline character of every line except the line from the last input file will be replaced with a tab character.

If an end-of-file condition is detected on one or more input files, but not all input files, paste will behave as though empty lines were read from the files on which end-of-file was detected, unless the -s option is specified.

 OPTIONS

The paste utility supports the XBD specification, Utility Syntax Guidelines  .

The following options are supported:

-d list
Unless a backslash character appears in list, each character in list is an element specifying a delimiter character. If a backslash character appears in list, 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 character, to replace the newline character of the input lines. The elements in list are used circularly; that is, when the list is exhausted the first element from the list is reused. When the -s option is specified:
  • The last newline character in a file will not be modified.
  • The delimiter will be reset to the first element of list after each file operand is processed.
When the -s option is not specified:
  • The newline characters in the file specified by the last file operand will not be modified.
  • The delimiter will be reset to the first element of list each time a line is processed from each file.
If a backslash character appears in list, it and the character following it will be used to represent the following delimiter characters:
\n
Newline character.
\t
Tab character.
\\
Backslash character.
\0
Empty string (not a null character). If \0 is immediately followed by the character x, the character X, or any character defined by the LC_CTYPE digit keyword (see the XBD specification, Locale  ), the results are unspecified.

If any other characters follow the backslash, the results are unspecified.

-s
Concatenate all of the lines of each separate input file in command line order. The newline character of every line except the last line in each input file will be replaced with the tab character, unless otherwise specified by the -d option.

 OPERANDS

The following operand is supported:
file
A pathname of an input file. If "-" is specified for one or more of the files, the standard input will be used; the standard input will be read one line at a time, circularly, for each instance of "-". Implementations support pasting of at least 12 file operands.

 STDIN

The standard input will be used only if one or more file operands is "-". See the INPUT FILES section.

 INPUT FILES

The input files must be text files, except that line lengths will be unlimited.

 ENVIRONMENT VARIABLES

The following environment variables affect the execution of paste:
LANG
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.
LC_ALL
If set to a non-empty string value, override the values of all the other internationalisation variables.
LC_CTYPE
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files).
LC_MESSAGES
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
NLSPATH
Determine the location of message catalogues for the processing of LC_MESSAGES .

 ASYNCHRONOUS EVENTS

Default.

 STDOUT

Concatenated lines of input files will be separated by the tab character (or other characters under the control of the -d option) and terminated by a newline character.

 STDERR

Used only for diagnostic messages.

 OUTPUT FILES

None.

 EXTENDED DESCRIPTION

None.

 EXIT STATUS

The following exit values are returned:
0
Successful completion.
>0
An error occurred.

 CONSEQUENCES OF ERRORS

If one or more input files cannot be opened when the -s option is not specified, a diagnostic message will be written to standard error, but no output will be written to standard output. If the -s option is specified, the paste utility will provide the default behaviour described in Utility Description Defaults .

 APPLICATION USAGE

When the escape sequences of the list option-argument are used in a shell script, they must be quoted; otherwise, the shell treats the \ as a special character.

Portable applications should only use the specific backslash escaped delimiters presented in this specification. Historical implementations treat \x, where x is not in this list, as x, but future implementations are free to expand this list to recognise other common escapes similar to those accepted by printf and other standard utilities.

Most of the standard utilities work on text files. The cut utility can be used to turn files with arbitrary line lengths into a set of text files containing the same data. The paste utility can be used to create (or recreate) files with arbitrary line lengths. For example, if file contains long lines:


cut -b 1-500 -n file > file1
cut -b 501- -n file > file2

creates file1 (a text file) with lines no longer than 500 bytes (plus the newline character) and file2 that contains the remainder of the data from file. Note that file2 will not be a text file if there are lines in file that are longer than 500 + {LINE_MAX} bytes. The original file can be recreated from file1 and file2 using the command:

paste -d "\0" file1 file2 > file

The commands:


paste -d "\0" ...
paste -d "" ...

are not necessarily equivalent; the latter is not specified by this specification and may result in an error. The construct \0 is used to mean "no separator" because historical versions of paste did not follow the syntax guidelines, and the command:

paste -d"" ...

could not be handled properly by getopt().

 EXAMPLES

  1. Write out a directory in four columns:
    
    ls | paste - - - -
    
    

  2. Combine pairs of lines from a file into single lines:
    
    paste -s -d "\t\n" file
    
    

 FUTURE DIRECTIONS

None.

 SEE ALSO

cut, grep, pr.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]