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 ?
I created a function for this. First argument is the output file, rest arguments are the files to be joined.
Usage:
I know this is an old question but for future reference. If you know that the files you want to join have a pattern like in the question here e.g.
file1 file2 file3 ... fileN
Then you can simply join them with this commandWhere output will be the series of the joined files which were joined in alphabetical order.
Join joins lines of two files on a common field. If you want to join more - do it in pairs. Join first two files first, then join the result with a third file etc.
One can join multiple files (N>=2) by constructing a pipeline of
join
s recursively:The
man
page ofjoin
states that it only works for two files. So you need to create and intermediate file, which you delete afterwards, i.e.:While a bit an old question, this is how you can do it with a single
awk
:This script assumes:
<field_number>
<field_number>
is a valid integer.