paste command with 10 practical examples

linux paste command is used to merge lines of files. In this paste command we have two options along with paste command -d and -s

-d = delimiters

-s = serial

Syntax

paste [options] files

Now are going to see how to make use of -d and -s options to combine different file output.

In this article we are going to use below two files for demonstrate purpose.

[root@TechTutorial ~]# cat arkitfile1
Tech
Tututorial
Arkit
WebServer
paste
command
[root@TechTutorial ~]# cat file2arkit
Tutorial
Tech
Linux
server
command

Joining multiple files using paste command

To join the file content side by side just we have to below command

[root@TechTutorial ~]# paste arkitfile1 file2arkit
Tech    Tutorial
Tututorial      Tech
Arkit   Linux
WebServer       server
paste   command
command

Joining multiple files separated by specified delimiter

In this example we are going to use comma(,) as delimiter

[root@TechTutorial ~]# paste -d, arkitfile1 file2arkit
Tech,Tutorial
Tututorial,Tech
Arkit,Linux
WebServer,server
paste,command
command,

Merging multiple files sequentially

To merge multiple files in sequentially we have to use -s option along with command as shown in below example

[root@TechTutorial ~]# paste -s arkitfile1 file2arkit
Tech    Tututorial      Arkit   WebServer       paste   command
Tutorial        Tech    Linux   server  command

Separate file data as 2 columns

Straight line of data will be shown as two separate columns example shown below

[root@TechTutorial ~]# cat arkitfile1   <===== Before 
Tech
Tututorial
Arkit
WebServer


[root@TechTutorial ~]# paste - - < arkitfile1   <== After
Tech    Tututorial
Arkit   WebServer

Join multiple lines as single line separated by comma delimiter

From below content

[root@TechTutorial ~]# cat arkitfile1
Tech
Tututorial
Arkit
WebServer
paste
command

Changed to below

[root@TechTutorial ~]# paste -d, -s arkitfile1
Tech,Tututorial,Arkit,WebServer,paste,command

Merging both file content alternatively

We have two files which are having number of lines merging them alternatively we have to use below command

[root@TechTutorial ~]# paste -d'\n' -s arkitfile1 file2arkit
Tech
Tututorial
Arkit
WebServer
paste
command
Tutorial
Tech
Linux
server
command

Merging file content separated by semicolon

[root@TechTutorial ~]# paste -d':' - - < arkitfile1
Tech:Tututorial
Arkit:WebServer

Merging a file into 3 columns using multiple delimiters

[root@TechTutorial ~]# paste -d:, - - - < arkitfile1
Tech:Tututorial,Arkit
WebServer:paste,command

Conclusion

We can make use of this command to merge lines of multiple files and modify as required using paste options -d and -s.

Thanks for the read.

What you feel about this article..? Any questions comment below

 

Thanks for your wonderful Support and Encouragement

Ravi Kumar Ankam

My Name is ARK. Expert in grasping any new technology, Interested in Sharing the knowledge. Learn more & Earn More

8 Responses

  1. Farista Singh says:

    very good explanation…

  2. blank Vinod says:

    Dear Sir

    thank you for uploading these various important information about linux & other topics . you are doing a great job i really appreciate oyur efforts as a learner your website is a very good medium to learn linux a to z course thank you for creating this awesome website

    Regards
    Vinod

  3. blank Vinod says:

    Now i have various question in mind i would like to know which Ubuntu operating system version is mostly used in companies & whenever i am going any link it gives me many version like desktop Ubuntu 16.04.1 LTS & Ubuntu 14.04.5 LTS & Ubuntu 12.04.5 LTS( in this it gives me like desktop version & server option so can you tell me that which option should i go for to download or else you can share me any link from where i can download the server version &
    second question is that in centos the same information is asking whenever i willing to download the centos also like many version with desktop & server also please share the link ASAP.
    third question is that how much RAM should i assign to these operating system in vmware

    • Any Version you can use, it depend upon the requirement which application your going to install and configure. Basic RAM requirement is 2GB, you can give more than 2GB its again depends on type of application and its usage.

Leave a Reply

Your email address will not be published. Required fields are marked *