Comparing two columns in two files using awk

后端 未结 2 1821
逝去的感伤
逝去的感伤 2021-01-14 23:38

I\'m trying to compare two different files, let\'s say \"file1\" and \"file2\", in this way. If fields $2 and $3 are the same in both files, print $0 of file2. Here\'s an ex

相关标签:
2条回答
  • 2021-01-15 00:01
    awk 'NR==FNR{a[$2,$3];next} ($2,$3) in a' file1 file2
    
    0 讨论(0)
  • 2021-01-15 00:02

    This awk should do:

    awk 'FNR==NR {a[$0];next} {for (i in a) if ($0~i) print}' file1 file2
    E 25 692 1 4
    E 510 744 1 8
    E 352 697 1 10
    

    It store the file1 in array a. Then loop trough file2 and test if it contains the data from array a, if yes, print the line.

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