paste—merges same lines of several files or subsequent lines of one file

paste filename1 filename2…
paste –d list filename1 filename2…
paste –s [ –d list ] filename1 filename2…

paste concatenates corresponding lines of the given input files filename1, filename2, etc. It treats each file as a column or columns of a table and pastes them together horizontally (see "cut" on page683).

Example A.42.
1  ls | paste - - -
2  paste -s -d"\t\n" testfile1 testfile2
3  paste file1 file2
				

Explanation

  1. Files are listed in three columns and glued together with a TAB.

  2. Combines a pair of lines into a single line using a TAB and new line as the delimiter, i.e., the first pair of lines are glued with a TAB; the next pair are glued by a newline, the next pair ...

Get Linux Shells by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.