There are different cases when we need to concatenate files by their columns. We may need each file's content to appear in separate columns. Usually, the cat
command concatenates in a line (or row-wise) fashion.
paste
is the command that can be used for column-wise concatenation. The paste
command can be used with the following syntax:
$ paste file1 file2 file3 …
Let's try an example as follows:
$ cat file1.txt 1 2 3 4 5 $ cat file2.txt slynux gnu bash hack $ paste file1.txt file2.txt 1slynux 2gnu 3bash 4hack 5
The default delimiter is tab. We can also explicitly specify the delimiter by using -d
. For example:
$ paste file1.txt file2.txt -d "," 1,slynux 2,gnu 3,bash 4,hack 5,