top | item 39621429

Ask HN: Regex on a File or Stream

1 points| buzzdenver | 2 years ago

I just ran into this seemingly not that hard issue of trying to match a multi-line regex against a 3Gb text file. What is the right tool for this? grep and perl failed running into PCRE limits.

6 comments

order

zaktoo2|2 years ago

Could you paste the regex portion of it please? Possibly some efficiencies to be gained there. You could also split the file into smaller chunks and then check the boundaries of the chunks.

buzzdenver|2 years ago

Yes, breaking it up would work, but that is not a solution for streams.

The regex is dead simple: /Authorization: Basic (.*)\ngrant_type=refresh_token/ "." does not match newline, so I'm basically looking two lines that conform to a template.

Specific cases can be transformed with some grep/awk magic, but IMO the concept of pattern matching against a stream is interesting regardless.

burntsushi|2 years ago

ripgrep should be able to handle it with the -U/--multiline flag.