paste can be used to horizontally merge the n-th corresponding lines from two or more input files (parallel merging, Format 1) or to successively merge all lines within a single file (serial merging, Format 2). The result is written to standard output.
Syntax
Format 1: | paste[ -d list] file ... |
Format 2: | paste -s[ -d list] file ... |
Joining the n-th lines of several files (parallel merging)
paste concatenates the n-th line of each input file, treating each file as a column or columns of a table. The corresponding lines are pasted together horizontally and displayed on the standard output (see Example 1). No option specified The tab character acts as a delimiter between columns
(delimiter) Uses a character from list as a delimiter between output columns. The characters in list are used consecutively and circularly, i.e. paste returns to the top of the list after using the last character in it. In parallel merging, lines from the last input file are always terminated with a newline character, not with a character from the list. Any string of arbitrary characters can be specified for list. The following escape sequences may also be used: \n (newline), \t (tab), \\ (backslash), and \0 (empty string, not a null character). If list contains escape sequences, blanks, or shell metacharacters, it must be enclosed in double quotes "...".
Name of the input file. This format of paste is only meaningful if you specify several files. If you use a dash (-) as the name for file, paste reads from standard input. |
Joining successive lines (serial merging)
(subsequent) For each input file, paste joins the lines together to form a single line and writes this line to standard output. By default, the lines from the input file are separated by tabs (see option d). Each output line is terminated by a newline character.
(d - delimiter) One of the characters from list is used in the output line instead of a tab to mark the joins between the input lines. The characters in list are used consecutively and circularly, i.e. paste returns to the top of the list after using the last character in it. Any string of arbitrary characters can be specified for list. The following escape sequences may also be used: \n (newline), \t (tab), \\ (backslash), and \0 (empty string, not a null character). If list contains escape sequences, blanks, or shell metacharacters, it must be enclosed in double quotes "...".
Name of the input file. You may name more than one file. |
Error
Output lines must not exceed 511 characters.
A maximum of 12 input files may be specified in format 1
|
Locale
The following environment variables affect the execution of paste: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization 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 internationalization 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), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other. 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 catalogs for the processing of LC_MESSAGES. |
Examples of Format 1
Example 1
The corresponding lines from the files numbers and letters are to be pasted together: The numbers file contains numbers from 1 to 100: 1 2 3 . . 100 The letters file contains lowercase letters from a to z: a b c . . z
|
Example 2
The current directory contains the following files:
The following command numbers these files (see the numbers file in Example 1):
|
Example 3
The current directory contains the same files as in Example 2. The following command lists the contents of the current directory in three columns. However, the columns will only be justified properly if the individual file names do not extend beyond the next tab stop.
How is this output produced? Compare the above command with the command
In this case, paste first reads the initial lines from all three files and pastes them into one line. When this is done, the second lines are read, etc. In the command |
Example 4
The current directory contains the same files as in example 2. As in example 3, you now wish to display the file names in three columns, but the second and third columns are to be separated by a colon instead of a tab.
|
Example of Format 2
Example 5
The customers file contains the following:
The following command joins only three lines of the customers file at a time. This is because a newline character is specified as a delimiter after every third input line:
|
See also
cut, grep, pr |