I\'d like to join two files in bash using a common column. I want to retain both all pairable and unpairable lines from both files. Unfortunately using
If join
command is not powerful enough I usually use sqlite if I need to perform such operations in shell.
You can easily import flat files to tables, then do SQL SELECT with proper JOIN.
Note, that with sqlite, you can utilize index to make the join even faster.
sqlite3 << EOF!
CREATE TABLE my table1 (.... -- define your table here
CREATE TABLE my table2 (.... -- define your table here
.separator "," -- define input field separator here if needed
.import input_file.txt mytable1
.import input_file.txt mytable2
SELECT ... JOIN ...
EOF!
sqlite is free and mutiplatform. Very handy.