1.同时在file1和file2中的行
awk '{if(ARGIND==1) {val[$0]}else{if($0 in val) print $0}}' file1 file2
2.只在file1中有的行.
awk '{if(ARGIND==1) {val[$0]}else{if($0 in val) delete val[$0]}}END{for(i in val) print i}' file1 file2
其实也可以这样:
awk 'ARGIND==1{a[$0]}ARGIND>1&&!($0 in a){print $0}' file1 file2
3.只在file2中有的行.
awk '{if(ARGIND==1) {val[$0]}else{if($0 in val) delete val[$0]}}END{for(i in val) print i}' file2 file1
阅读(1353) | 评论(0) | 转发(0) |