我先把脚本贴出来,然后我们一步步验证。
[root@abao67 ~]# vim abao.sh
#!/bin/bash #读取file1和file2文件相同是手机号码并输出到文件名为abao文件中 while read line do num=$(grep $line file2 | wc -l) if (($num > 0)) then echo $line >> tmp fi done < file1 awk '{print $0}' tmp | sort | uniq >abao rm -rf tmp
file1内容有如下:
[root@abao67 ~]# cat file1 13223852098 13223852018 13223852038 13223852048 13223852098 13223852068 13223852028 13223852048 13223852098 13223852068 13223852098 13223852018 07553338175 13669862978 13223852098 13223852038 13223852088 13223852038 13223852028 13223852098 13223852038 13223852088
file2内容如下:
13223852098 13223852098 13223852038 13223852088 13223852018 13223852038 13223852028 13223852068 13223852098 13223852018 13223852048 13223852098 13839685738 13223852068 13223852098 13223852018 03712889099 13839685738 13223852038 13223852028 13223852098 13223852038 13223852088
执行结果并查看验证如下:
[root@abao67 ~]# sh +x abao.sh [root@abao67 ~]# cat abao 13223852018 13223852028 13223852038 13223852048 13223852068 13223852088 13223852098
至此大功告成,欢迎网友提出bug,有问题请留言给我,谢谢!
本文 暂无 评论