paste Command: Tutorial & Examples

Combine lines of files

The paste command in Linux is a command-line utility used to merge lines of multiple files into a single file. It reads data from the specified files, one line at a time, and writes the lines to the standard output, separated by a specified delimiter. The basic syntax of the command is: paste [options] file1 [file2 ...]

The -d option is used to specify a delimiter, which separates the lines from the different files. The default delimiter is the tab character.

For example, the command paste file1.txt file2.txt will concatenate the contents of file1.txt and file2.txt, and the output will be written to the standard output. If file1.txt contains the lines line1, line2 and line3 and file2.txt contains the lines line4, line5 and line6, the resulting output will be: "line1 line4", "line2 line5", "line3 line6".

The -s option can be used to concatenate the contents of all the files horizontally(side by side) instead of vertically.

The paste command can be useful for combining data from multiple files into a single file for further processing, or for creating a single file from a series of smaller files.

Except where otherwise noted, content on this site is licensed under a CC BY-SA 4.0 license CC BY SA