1.在B中同时也在A中,comm_a_b.sh
sort -nu A > /tmp/A.txt
sort -nu B > /tmp/B.txt
awk 'NR==FNR{a[$1]=$2} NR>FNR {if($1 in a){print $0}}' /tmp/A.txt /tmp/B.txt > /tmp/result.txt
2.在B中,不在A中,diff_in_b_not_in_a.sh
sort -nu A > /tmp/A.txt
sort -nu B > /tmp/B.txt
awk 'NR==FNR{a[$1]=$2} NR>FNR {if(!($1 in a)){print $0}}' /tmp/A.txt /tmp/B.txt > /tmp/result.txt
本文介绍使用Shell脚本进行两个文件的内容对比方法,包括找出两文件中共有的内容及找出仅存在于其中一个文件中的内容。通过sort和awk命令组合实现高效的数据处理。
45

被折叠的 条评论
为什么被折叠?



