Merge files line by line

To merge files line by line, you can use the paste command. By default, the corresponding lines of each file are separated with tabs. This command is the horizontal equivalent to the cat command, which prints the content of the two files vertically.

Let’s say that we have two files, file_1 and file_2:

linux example files for the paste command

We can merge these two files with the paste command:

linux paste command

In the example above you can see that the paste command merged the content of both files. The content has been separated with tabs.

We can specify a different delimiter using the -d option:

linux the paste command with different delimiter

In the example above you can see that we have specified the / character as the delimiter.

Another useful feature of this command is that the output can be presented in a horizontal fashion using the -s option:

linux the paste command horizontal output

In the picture above you can see that the alignment of the second column is a little bit off. That is because the first column’s line lengths are not even.

Subscribe to our Newsletter

Like us on Facebook

top
Geek University 2019