Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Aug 2010 18:44:41 +0200 (CEST)
From:      Oliver Fromme <olli@lurza.secnetix.de>
To:        freebsd-questions@FreeBSD.ORG, jacks@sage-american.com, johnl@iecc.com
Subject:   Re: Grepping a list of words
Message-ID:  <201008121644.o7CGiflh099466@lurza.secnetix.de>
In-Reply-To: <20100812153535.61549.qmail@joyce.lan>

next in thread | previous in thread | raw e-mail | index | archive | help
John Levine <johnl@iecc.com> wrote:
 > > > % egrep 'word1|word2|word3|...|wordn' filename.txt
 > 
 > > Thanks for the replies. This suggestion won't do the job as the list of
 > > words is very long, maybe 50-60. This is why I asked how to place them all
 > > in a file. One reply dealt with using a file with egrep. I'll try that.
 > 
 > 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.

My guess is that one large regular expression is more
efficient than many small ones.  But I haven't done real
benchmarks to prove this.

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

"To this day, many C programmers believe that 'strong typing'
just means pounding extra hard on the keyboard."
        -- Peter van der Linden



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201008121644.o7CGiflh099466>