Joining two files with multiple columns via AWK

后端 未结 1 1586
萌比男神i
萌比男神i 2021-01-16 09:11

First of all, I must apologise : I know there\'s a lot of various topics that already answer my question, but as you\'ll see by yourself, AWK isn\'t really a big friend of m

1条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-16 10:00

    awk '
        NR==FNR {A[$1,$3,$6] = $0; next} 
        ($1 SUBSEP $2 SUBSEP $3) in A {print A[$1,$2,$3], $4}
    ' A.txt B.txt
    

    That requires the whole file A.txt to be stored in memory. If B.txt is significantly smaller

    awk '
        NR==FNR {B[$1,$2,$3] = $4; next}
        ($1 SUBSEP $3 SUBSEP $6) in B {print $0, B[$1,$3,$6]}
    ' B.txt A.txt
    

    0 讨论(0)
提交回复
热议问题