I am using egrep (grep -E
) with a PATTERN file. (-f path/to/file
).
This is done in an infinite loop on a stream of text. This implies that I cannot accumulate and pass ALL the input to grep at once (like *.log
).
Is there a way to make grep "save" the NFA it is building from the PATTERN file to use for it's next run?
I have searched Google and read the documentation with no luck.
I'll try to explain it a little bit more. I need to locate a fixed number of strings with regexes (This is not a part of a question but feel free to suggest otherwise) such as IP addresses, domains etc. The search is done on a feed from the internet. You can think about it as a stream of text.
I can't use grep
on all of the input since it's a stream.
I can accumulate a chunk of stream and use grep
on it (thus not using grep
on each line) but this is also limited (let's say for 30 seconds).
I know grep
is building an NFA from all of its patterns (in my case from a file).
So my question here is: can I tell grep
to save that NFA for the next run, since it is not going to change? That would save me the time of building that NFA every time.
grep
per line of text? Where is the text coming from? Wouldtail -f
be an option?grep
on that chunk.grep
several times. Possibly related: Why is matching 1250 strings against 90k patterns so slow?grep
is meant to work on a stream of text, I still don't get why you'd need to run several instances. Why can't you feed all those to the samegrep
instance? Why do you need to accumulate them before feeding togrep
?