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:
We can merge these two files with the 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:
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:
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.