On Tue, 16 Nov 2010, Mike Miller wrote:

> On Tue, 16 Nov 2010, Justin Krejci wrote:
>
> Thanks for the tip.  I had tried "grep -f", but it was slower.  I didn't 
> know about "grep -F", but I just tried it and it also is slower:
>
> time echo -e "A\nB" | grep -F - data_file | grep -E "(A|B).*(A|B)"
>
> real    2m44.955s
> user    2m51.399s
> sys     0m2.174s


A guy on another list came up with the best overall solution so far.  It 
isn't quite as fast as my tricky "tee"-based method:

time fgrep -e A -e B data_file | grep -E '(A|B).*(A|B)'

real    0m6.411s
user    0m6.205s
sys     0m0.621s


That's only about 1.5 seconds slower than my fastest method, but my 
fastest method is a complicated mess.  This method is very simple and easy 
to remember.  It's something you can use.  Also, I'm pretty sure that it 
is the fastest method on a single-core.  The "tee" method was faster 
*only* because it was doing parallel processing on two cores.

Mike