From owner-freebsd-questions@FreeBSD.ORG Thu Aug 12 16:44:59 2010 Return-Path: Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 754FA10656A9 for ; Thu, 12 Aug 2010 16:44:59 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [IPv6:2a01:170:102f::2]) by mx1.freebsd.org (Postfix) with ESMTP id D55808FC16 for ; Thu, 12 Aug 2010 16:44:58 +0000 (UTC) Received: from lurza.secnetix.de (localhost [127.0.0.1]) by lurza.secnetix.de (8.14.3/8.14.3) with ESMTP id o7CGifJc099467; Thu, 12 Aug 2010 18:44:56 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.14.3/8.14.3/Submit) id o7CGiflh099466; Thu, 12 Aug 2010 18:44:41 +0200 (CEST) (envelope-from olli) Date: Thu, 12 Aug 2010 18:44:41 +0200 (CEST) Message-Id: <201008121644.o7CGiflh099466@lurza.secnetix.de> From: Oliver Fromme To: freebsd-questions@FreeBSD.ORG, jacks@sage-american.com, johnl@iecc.com In-Reply-To: <20100812153535.61549.qmail@joyce.lan> X-Newsgroups: list.freebsd-questions User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (FreeBSD/6.4-PRERELEASE-20080904 (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.3.4 (lurza.secnetix.de [127.0.0.1]); Thu, 12 Aug 2010 18:44:57 +0200 (CEST) Cc: Subject: Re: Grepping a list of words X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-questions@FreeBSD.ORG, jacks@sage-american.com, johnl@iecc.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2010 16:44:59 -0000 John Levine 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