搜索日志文件 [英] Searching a log file
问题描述
可能重复:
在VIM或其他地方使用Regex搜索
我正在搜索一个巨大的〜600 Mb文件的特定模式,它是7个十六进制值长。问题是
I'm searching a huge ~600 Mb file for a particular pattern which is 7 Hexadecimal values long. The Problem is
- 模式可能在下一行,
- 地址线。
我摆脱了所有的回车问题1,但我仍然面临即使值下一行我不知道如何搜索过去的地址行。以下是一个示例:
0x000001A0:36 5B 09 76 99 31 55 09 78 99 34 51 49 BF E0 03
0x000001B0:28 0B 0A 03 0B E0 07 28 0B 0A 03 0B 49 58 09 35
I got rid of problem 1 by getting rid of all the carriage returns but I'm still faced with even if the values are on the next line I have no idea how to search past the address line. Below is an example:
0x000001A0: 36 5B 09 76 99 31 55 09 78 99 34 51 49 BF E0 03
0x000001B0: 28 0B 0A 03 0B E0 07 28 0B 0A 03 0B 49 58 09 35
想要能够找到模式 49 BF E0 03 28 0B 0A
,这是跨过上面的第1和第2行,但我不能只是定期搜索,因为 0x000001B0:
在行的开头任何建议或c ++代码或excel想法将有所帮助。我现在正在使用VIM打开这个大文件,并使用excel不会打开整个东西。
For example: I want to be able to find the pattern 49 BF E0 03 28 0B 0A
, Which goes across lines 1 and 2 above but I can't just search for it regularly because of the 0x000001B0:
at the beginning of the line Any suggestions or c++ code or excel ideas would be helpful. I'm using VIM at the moment to open this big file and using excel won't open the entire thing.
推荐答案
Python ,只是读入行,拆分,吸取第一部分,将十六进制串入一个字符串,并搜索。这样的工作:
Python, just read in line, split, chuck the first part, concat the hex into a string, and search. Something like this would work:
hex = ""
for each line in lines:
tmp = line.split() // split on whitespace
hex += tmp[1:] // grab everything after address
if hex.contains(pattern):
# do something
或者使用正则表达式,但你得到了基本的想法。
Or use a regex, but you get the basic idea.
这篇关于搜索日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!