Searching a log file [duplicate]
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
- the 'pattern' could be on the next line and
- 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.
- Open the file
- Read a line
- Read address and discart it
- Read first value and put it into the buffer
- Read next value, and throw last value of the buffer (std::list could be good for that)
- Check if buffer contains the pattern
- Loop through 5 up to the end of the line
- Loop through 2 up to the end of the file
精彩评论