prathmesh.kallurkar prathmesh.kallurkar - 1 month ago 14
Linux Question

join multiple files

I am using the standard join command to join two sorted files based on column1.
The command is simple join file1 file2 > output_file.

But how do I join 3 or more files using the same technique ?
join file1 file2 file3 > output_file
Above command gave me an empty file.
I think sed can help me but I am not too sure how ?

Answer Source

man join:

       join - join lines of two files on a common field

       join [OPTION]... FILE1 FILE2

it only works with two files.

if you need to join three, maybe you can first join the first two, then join the third.


join file1 file2 | join - file3 > output

that should join the three files without creating an intermediate temp file. - tells the join command to read the first input stream from stdin