Showing posts with label paste command in linux. Show all posts
Showing posts with label paste command in linux. Show all posts

How to merge contents of 2 files using paste?

This is one of the best command that facilitates the system admin to perform his specific tasks. Below is the list with the examples showing the paste command.

[localhost@localhost ~]$ cat file1
apple
orange
mango
banana

[localhost@localhost ~]$ cat file2
coldplay
westlife
michael
sunibigyana
piyush

[localhost@localhost ~]$ paste -s file1
apple    orange    mango    banana

[localhost@localhost ~]$ paste -d, -s file1
apple,orange,mango,banana

[localhost@localhost ~]$ paste - - < file1
apple    orange
mango    banana

[localhost@localhost ~]$ paste -d':' - - < file1
apple:orange
mango:banana

[localhost@localhost ~]$ paste - - - < file1
apple    orange    mango
banana
   
[localhost@localhost ~]$ paste -d ':,' - - - < file1
apple:orange,mango
banana:,

[localhost@localhost ~]$ cat file2
coldplay
westlife
michael
sunibigyana
piyush

[localhost@localhost ~]$ paste file1 file2
apple    coldplay
orange    westlife
mango    michael
banana    sunibigyana
    piyush

[localhost@localhost ~]$ paste -d, file1 file2
apple,coldplay
orange,westlife
mango,michael
banana,sunibigyana
,piyush

[localhost@localhost ~]$ cat file2 | paste -d, file1 -
apple,coldplay
orange,westlife
mango,michael
banana,sunibigyana
,piyush

[localhost@localhost ~]$ cat file1 | paste -d, - file2
apple,coldplay
orange,westlife
mango,michael
banana,sunibigyana
,piyush

[localhost@localhost ~]$ cat file1 file2 | paste -d, - -
apple,orange
mango,banana
coldplay,westlife
michael,sunibigyana
piyush,

[localhost@localhost ~]$ paste -d'\n' file1 file2
apple
coldplay
orange
westlife
mango
michael
banana
sunibigyana

piyush
[localhost@localhost ~]$