我有兩個文件得到以下信息。我需要比較FILE2中匹配的文件和打印行。使用awk比較兩個文件並打印匹配的行
FILE1.TXT
martin01
kevin01
phoenix01
samson01
edward01
FILE2.TXT
martin01.test.com empid: 9874712
martin01.test1.com empid:0972292
kevin01.test.com empid: 3297203
kevin01.test.com empid: 3297203
phoenix01.test.com empid: 9872219
phoenix01.test1.com empid:9803994
samson01.test.com empid: 0983903
samson01 empid: 7665758
edward01.test.com empid: 0979072
edward01.test2.com empid: 748840
gregory01.test.com empid: 657758
clevin01.test.com empid:6589598
預期的輸出應該是這樣的:
martin01.test.com empid: 9874712
martin01.test1.com empid:0972292
kevin01.test.com empid: 3297203
kevin01.test.com empid: 3297203
phoenix01.test.com empid: 9872219
phoenix01.test1.com empid:9803994
samson01.test.com empid: 0983903
samson01 empid: 7665758
edward01.test.com empid: 0979072
edward01 empid: 748840
這是我寫的,但它的某處錯誤..
awk 'FNR==NR {a[$1]; next} $1 in a' FILE1.txt FILE2.txt
爲什麼選擇edward01 empid?它不是edward01.test2.com empid? – 2016-04-08 20:12:18