Searching a log file [duplicate]

拈花ヽ惹草 提交于 2019-12-20 01:42:33

问题


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.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/6413361/searching-a-log-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!