[python]比较文件内容脚本

案例要求:

1.现在有a.log和b.log两个文件
2.两个文件里有大量的重复的数据
3.取出只有在b.log中存在的行

编写python脚本,实现如上功能

with open('a.log') as f1:  
    aset = set(f1)
with open('b.log') as f2:
    bset = set(f2)
with open('/tmp/result.txt','w') as f3:
    f3.writelines(bset - aset)

猜你喜欢

转载自blog.csdn.net/qq_44839276/article/details/94875454
今日推荐