In *nix terminal (Bash) os there any other faster way to find a pattern (or excluding them - egrep -v option) than using this:
grep -f {patternfile} {source}
Using this option is painfully slow for larger files.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIf your patterns are fixed strings, have a look at agrep (download) (or other matchers that are based on the Wu-Manber algorithm). It will match all patterns in parallel.
Wu-Manber is generally good for up to a few hundred thousand patterns (maybe a million at a push).
For regular expressions I think there's no generally fast approach.
-f
Aug 16, 2013 at 11:01
You don't specify what type of file you're searching through but another tool that I've seen used for searching which might give you better performance is ack
.
It doesn't however provide the ability to search using a pattern file. However you can use this approach to coax ack
into searching for multiple patterns like so:
$ grep -Ffx <(ack -l "pattern1" file) <(ack -l "pattern2" file)
This could easily be put into a Bash script making it more general purpose.
LC_ALL=C grep -f patternfile source
if applicablebash
tool?