Grepping a list of words

John R. Levine johnl at
Thu Aug 12 18:06:06 UTC 2010

> > Gee, 50 words, that's about a 300 character pattern, that's not a problem
> > for any shell or version of grep I know.
> >
> > But reading the words from a file is equivalent and as you note most
> > likely easier to do.
> The question is what is more efficient.  This might be
> important if that kind of grep command is run very often
> by a script, or if it's run on very large files.

It's exactly the same, since it's the same program using the same search 
algorithm.  The only thing that's different is the input language for the 
pattern.  What looks like a bunch of separate patterns in the input file 
is internally turned into one pattern that is then compiled into a state 
machine that it uses to match the input.


More information about the freebsd-questions mailing list