开发者

Searching a log file [duplicate]

This question already has answers here: 开发者_如何转开发 Closed 11 years ago.

Possible Duplicate:

Searching using Regex in VIM or elsewhere

I'm searching a huge ~600 Mb file for a particular pattern which is 7 Hexadecimal values long. The Problem is

  1. the 'pattern' could be on the next line and
  2. there are several addressing lines.

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

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, 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.


You could use a circular buffer.

  1. Open the file
  2. Read a line
  3. Read address and discart it
  4. Read first value and put it into the buffer
  5. Read next value, and throw last value of the buffer (std::list could be good for that)
  6. Check if buffer contains the pattern
  7. Loop through 5 up to the end of the line
  8. Loop through 2 up to the end of the file
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜