join in bash like in SAS

后端 未结 2 834
无人共我
无人共我 2021-01-14 18:10

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

2条回答
  •  耶瑟儿~
    2021-01-14 18:53

    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.

提交回复
热议问题