Merge corresponding or subsequent lines of files (POSIX)
paste [-d list] [-s] file...
Character | Represents |
---|---|
\n | newline character |
\t | tab character |
\\ | backslash character |
\0 | empty 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.
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.
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
The input files are text files.