awk比较两个文件的异同

时间:2021-09-03 19:05:25
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






awk '{if(NR==FNR){val[$0]}else{if($1 in val) print $0}}' 70029  zhima






awk '{if(NR==FNR){val[$0]=$0}else{if($5 in val) {print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7"\t1"}else{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7"\t0"}}}'  from data