awk Compare 2 files, print match and difference

前端 未结 2 1663
日久生厌
日久生厌 2020-12-22 12:14

I need to comapre two files f1.txt and f2.txt and obtain matches, and non-matches, for this case I am looking to match first field on both files. And print first the second

相关标签:
2条回答
  • 2020-12-22 12:48

    This was very useful . I have changed a bit to get data between 2 files and only have 1 column in each file .

    awk 'BEGIN { OFS=FS=";" } FNR==NR { array[$1]=$1; next } { print ($1 in array ? array[$1] : "Not Found"), $0 }' file1 file2
    
    0 讨论(0)
  • 2020-12-22 12:50

    This should do:

    awk -F";" 'NR==FNR{a[$1]=$2;next}{if (a[$1])print a[$1],$0;else print "Not Found", $0;}' OFS=";" f2.txt f1.txt
    
    0 讨论(0)
提交回复
热议问题