paste

merge corresponding or subsequent lines of files (POSIX)

Syntax:

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

Options:

-d list
Use the one or more characters specified in list to separate corresponding lines in the output (default delimiter is tab). If list contains multiple characters, the characters are used circularly; i.e. when the list is exhausted, the first character from the list is reused. You can use the following special characters in list:
Character Represents
\nnewline character
\ttab character
\\backslash character
\0empty string (not a null character)

In parallel merging (no -s option), the lines from the last file always end with a newline character instead of the one specified in list.

-s
Merge the subsequent lines of each separate input file into a single line. When paste finishes merging all the lines in one file, it forces a new line and then merges the lines of the next file. A tab separates the merged lines unless you specify another character with option -d. Regardless of the list used with -d, the last character of the file is always a newline character.
file
The pathname of a text file, whose contents are used instead of the standard input. If a dash (-) is specified for one or more of the filenames, the standard input is used; the standard input is read one line at a time, round-robin, for each instance of a dash (-).

Examples:

List a directory in one column:

    ls -C | paste -d" " -

List a directory in four columns:

    ls | paste - - - -

Combine pairs of lines from myfile into single lines, separated by a tab:

    paste -s -d "\t\n" myfile

The following examples show how paste operates on two simple files, each containing four lines:

myfile contains the following:

    fred
    barney
    wilma
    dino

yourfile contains the following:

    george
    judy
    jane
    astro

Executing paste myfile yourfile results in:

    fred    george
    barney  judy
    wilma   jane
    dino    astro

Executing paste -s myfile yourfile results in:

    fred    barney  wilma    dino
    george  judy    jane     astro

Description:

The paste utility reads input files, concatenates their corresponding lines, and writes the resulting lines to the standard output.

By default, paste treats each file as a column and places the columns side by side. This is known as "parallel merging." If -s is specified, however, paste combines the subsequent lines of each input file into a single line. This is known as "serial merging."

Output lines are separated by the tab character unless another delimiter is specified by option -d.

Exit status:

0
Successful completion.
>0
An error occurred.

Files:

The input files are text files.

See also: