100 Useful Command-Line Utilities

by Oliver; 2014

40. paste

paste joins files together in a column-wise fashion. Another way to think about this is in contrast to cat, which joins files vertically. For example:
$ cat file1.txt
a
b
c
$ cat file2.txt
1
2
3
$ paste file1.txt file2.txt
a	1
b	2
c	3
Paste with a delimiter:
$ paste -d";" file1.txt file2.txt
a;1
b;2
c;3
As with cut, paste's non-unix namesake on Macintosh—printing text from the clipboard—is a different beast entirely.

A neat feature of paste is the ability to put different rows of a file on the same line. For example, if the file sample.fa is:
>TCONS_00046782
FLLRQNDFHSVTQAGVQWCDLGSLQSLPPRLKQISCLSLLSSWDYRHRPPHPAFFLFFFLF
>TCONS_00046782
MRWHMPIIPALWEAEVSGSPDVRSLRPTWPTTPSLLKTKNKTKQNISWAWCMCL
>TCONS_00046782
MFCFVLFFVFSRDGVVGQVGLKLLTSGDPLTSASQSAGIIGMCHRIQPWLLIY
(This is fasta format from bioinformatics). Then:
$ cat sample.fa | paste - -
>TCONS_00046782	FLLRQNDFHSVTQAGVQWCDLGSLQSLPPRLKQISCLSLLSSWDYRHRPPHPAFFLFFFLF
>TCONS_00046782	MRWHMPIIPALWEAEVSGSPDVRSLRPTWPTTPSLLKTKNKTKQNISWAWCMCL
>TCONS_00046782	MFCFVLFFVFSRDGVVGQVGLKLLTSGDPLTSASQSAGIIGMCHRIQPWLLIY
And you can do this with as many dashes as you like.

<PREV   NEXT>