linux文件列匹配实例
使用文件b.txt匹配a.txt的某一列
[hadoop@test]$ cat a.txt
1 2
2 3
1 3
2 5
6 7
22 3
[hadoop@test]$ cat b.txt
1
2
4
7
[hadoop@test]$ awk ‘NR==FNR{a[$1];next}{if($1 in a)print }’ b.txt a.txt
1 2
2 3
1 3
2 5
[hadoop@test]$ awk ‘NR==FNR{a[$1];next}{if($2 in a)print }’ b.txt a.txt
1 2
6 7
[hadoop@test]$ awk ‘NR==FNR{a[$1];next}{if(($1 in a)||($2 in a))print }’ b.txt a.txt
1 2
2 3
1 3
2 5
6 7