From owner-freebsd-questions@FreeBSD.ORG Thu Aug 12 17:09:52 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 B44751065696 for ; Thu, 12 Aug 2010 17:09:52 +0000 (UTC) (envelope-from swell.k@gmail.com) Received: from mail-bw0-f54.google.com (mail-bw0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id 683598FC1E for ; Thu, 12 Aug 2010 17:09:49 +0000 (UTC) Received: by bwz9 with SMTP id 9so1334956bwz.13 for ; Thu, 12 Aug 2010 10:09:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:references :date:in-reply-to:message-id:user-agent:mime-version:content-type; bh=BokqWsIxiHaNlWZ7mF83bW0AMzk5MJ3OQ1LXQHGWNNU=; b=q/Hb8zOlPFkJ+BWWEpaq3C7tnHdpOaFvANAySVd7b9HK7QEGGNQ67HJRIhuuQHKT69 X+Ia/9WjZi0Lf+lLxk1neEIOSaOEoGeBf3owHXV3ZLvDBpGjYK7DdGEtLkqahpIgwaub ZFJR9N3mjDU1ApyKBLmbUxzuPPUAOSvFJSmm4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; b=uLWKbBJIC4pT1gaZR1hfeC+gQUyuqeAiQ5xDaw63Q2LUwJk1R8/4mZXWUSvXly52pW u9Lv57zxgMAHKpuoAIdeUErbWnosSUE/mrXj8w9m7k/g5wOj+s9Uc6Sai0l8JADG90BA I4sRny2zgDOn2FAxbhw6V8Zs8lWXsf77iY3qE= Received: by 10.204.138.145 with SMTP id a17mr265545bku.82.1281632988184; Thu, 12 Aug 2010 10:09:48 -0700 (PDT) Received: from localhost ([94.75.253.73]) by mx.google.com with ESMTPS id f18sm1201955bkf.3.2010.08.12.10.09.43 (version=SSLv3 cipher=RC4-MD5); Thu, 12 Aug 2010 10:09:46 -0700 (PDT) From: Anonymous To: freebsd-questions@FreeBSD.ORG References: <20100812153535.61549.qmail@joyce.lan> <201008121644.o7CGiflh099466@lurza.secnetix.de> Date: Thu, 12 Aug 2010 21:09:37 +0400 In-Reply-To: <201008121644.o7CGiflh099466@lurza.secnetix.de> (Oliver Fromme's message of "Thu, 12 Aug 2010 18:44:41 +0200 (CEST)") Message-ID: <867hjv92r2.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: jacks@sage-american.com Subject: Re: Grepping a list of words X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Aug 2010 17:09:52 -0000 Oliver Fromme writes: > 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. BTW, not using regular expressions is even more efficient, e.g. $ fgrep -f /usr/share/dict/words /etc/group When using egrep(1) it takes considerably more time and memory.