Lum – How to combine contents of two files having the same value in a column

columnsjoin;text processing

File1:

00:00 274
00:04 476
00:05 450
00:06 499
00:07 373
00:08 206
00:09 471
00:10 154

File2:

00:00 183
00:01 60
00:02 344
00:03 540
00:04 450
00:07 348
00:09 473
00:10 203

Desired output:

00:00,274,183
00:01,0,60
00:02,0,344
00:03,0,540
00:04,476,450
00:05,450,0
00:06,499,0
00:07,373,348
00:08,206,0
00:09,471,473
00:10,154,203

Column 1 of each file will be checked and if same, values will be joined to the output. Please note the "0" value for those contents not present on either file. Also, this will be used for combining contents of 6 files.

Best Answer

Assuming the input files are alphabetically sorted on their join field (as they are in your sample):

join -e0 -a1 -a2 -o 0,1.2,2.2 file1 file2 | tr ' ' ,
Related Question