Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

join multiple files

Tags:

linux

join

sed

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 ?

like image 373
prathmesh.kallurkar Avatar asked May 23 '12 19:05

prathmesh.kallurkar


People also ask

How do I join multiple files?

Click the Select files button above, or drag and drop files into the drop zone. Select the files you want to merge using the Acrobat PDF combiner tool. Reorder the files if needed. Click Merge files.

How do I merge multiple files in Unix?

Replace file1 , file2 , and file3 with the names of the files you wish to combine, in the order you want them to appear in the combined document. Replace newfile with a name for your newly combined single file. This command will add file1 , file2 , and file3 (in that order) to the end of destfile .

How do I join files in Linux?

To join two or more text files on the Linux command-line, you can use the cat command. The cat (short for “concatenate”) command is one of the most commonly used commands in Linux as well as other UNIX-like operating systems, used to concatenate files and print on the standard output.


1 Answers

man join:

NAME
       join - join lines of two files on a common field

SYNOPSIS
       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.

try:

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

like image 151
mata Avatar answered Sep 26 '22 13:09

mata