现在两个文件格式如下:
test1:
aaa
bbb
ddd
test2:
aaa|1000
bbb|2000
ccc|3000
ddd|4000
awk -F'|' 'NR==FNR{a[$1]++}NR!=FNR{if($1 in a){print}}' test1.txt test2.txt
test1:
aaa
bbb
ddd
test2:
aaa|1000
bbb|2000
ccc|3000
ddd|4000
awk -F'|' 'NR==FNR{a[$1]++}NR!=FNR{if($1 in a){print}}' test1.txt test2.txt