Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find a result that involve more lines in the file #20

Open
FulvioSpelta opened this issue Nov 28, 2018 · 0 comments
Open

Find a result that involve more lines in the file #20

FulvioSpelta opened this issue Nov 28, 2018 · 0 comments

Comments

@FulvioSpelta
Copy link

Hi all, I kindly ask for a support. I need to search in mid-size text files (one at the time, 50/60 MB size) for regexp that search for 2 strings one "near" the other.
The use case is to automatically search for patterns (request/answer) in log files.

Example:
text file fragment

000000: USB-SERIAL CH340 (COM12), 2018-11-26 17:35:54,3748068
 0A 03 00 00 00 17 04 BF                           .......¿
000001: USB-SERIAL CH340 (COM10), 2018-11-26 17:35:54,9676068 +0,5928000
 0A 03 2E 00 01 00 00 00 18 00 18 00 19 00 18 00   ................
 19 00 31 00 01 00 01 00 01 00 01 01 CC 70 DE C3   ..1.........ÌpÞÃ
 4F 95 02 00 00 00 00 00 00 00 00 00 00 00 00 0C   O•..............
 B7 E5 45                                          ·åE

First i search for the request pattern using theexample code with this "regexp" and i find the expected result:

findInFiles.find({'term': "0A 03 00 00 00 17 04 BF", 'flags': 'gm'}, '.', '.txt$')
found "0A 03 00 00 00 17 04 BF" 752 times in "181127_0944_ReqView.txt"

Then i search for the req/ans pattern where the result involve search in multiple lines and it finds nothing:

findInFiles.find({'term': "0A 03 00 00 00 17 04 BF\W+(?:\w+\W+){1,40}? 0A 03 2E", 'flags': 'gm'}, '.', '.txt$')

Using the same regexp in notepad++ search returns the expected results:
image

Can someone kindly give me an hint (i'm not an expert programmer i'm writing just few lines of code to automate field tests) ?
Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant