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