I am trying to search through a hex dump for matching hex strings, ie in testHexData.txt there might be-20F09FE520F09FE51CF09FE518F09FE514F09FE50000A0E10CF09FE508F09FE5CEFABEBA300B00007C000028700000284900A0E3CC0100EB080200EA8716A0E3020BA0E3010080E000D0A0E194499FE5000094E5000050E30200000AC20100EB044084E2F9FFFFEA10089FE5000090E5F00000E28716A0E30000 and in testHex.txt there would be strings that may or may not be in testHexData.txt, eg. 20F09FE、518F09FE、FGG7988H等。
我找到了以下代码,当要搜索的数据是列表格式时有效,即猪狗猫,但如果要搜索的数据是连续字符串,则无效。代码运行没有任何错误,但不会产生结果。我确信解决方案很简单,但我正在兜圈子试图找到它。我将不胜感激任何帮助。谢谢 :)
file1 = set(line.strip() for line in open(r'C:\Python27\testHexData.txt'))
file2 = set(line.strip() for line in open(r'C:\Python27\testHex.txt'))
for line in file1 & file2:
if line:
print line