[Python] 找寻A文件中有而B文件中没有的记录
举个简单例子。比如a.log文件中有地址记录
...
0x68CF94B0
0x68CF94B4
0x68CE94D8
0x68CF7460
...
b.log中有地址记录
...
0x68CE94D8
0x68CF94B0
...
运行脚本:
#!/usr/bin/pythonimport rea_file = open("a.log", 'r')b_file = open("b.log", 'r')addr_set = set()for line in b_file.readlines():# print line result = re.search(r"(0x[\dA-F]+)", line) if (result != None): addr = result.group(1) addr_set.add(addr)# print addrfor line in a_file.readlines(): result = re.search(r"(0x[\dA-F]+)", line) if (result != None): addr = result.group(1) if (addr not in addr_set): print "Found:%s" % linea_file.close()b_file.close()
得到a.log中有而b.log中没有的地址记录:
Found:0x68CF94B4
Found:0x68CF7460