Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 Sep 2022 08:40:05 +0200
From:      Andreas Kusalananda =?utf-8?B?S8OkaMOkcmk=?= <andreas.kahari@abc.se>
To:        Steve O'Hara-Smith <steve@sohara.org>
Cc:        questions@freebsd.org
Subject:   Re: Slightly OT: How to grep for two different things in a file
Message-ID:  <YxmORar5xf1mU2c2@harpo.local>
In-Reply-To: <20220908073350.2c16bf4e2c908c0ad007af3e@sohara.org>
References:  <CAGBxaXn6ZO-e0746fwzNp%2Bv-6bAucjxePMOt-mEv2HKmkCBXcg@mail.gmail.com> <YxkhieQ2omb3sr5s@harpo.local> <20220908073350.2c16bf4e2c908c0ad007af3e@sohara.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Sep 08, 2022 at 07:33:50AM +0100, Steve O'Hara-Smith wrote:
> On Thu, 8 Sep 2022 00:56:09 +0200
> Andreas Kusalananda Kähäri <andreas.kahari@abc.se> wrote:
> 
> > 	find src/java -type f \
> > 		-exec grep -qF 'tid' {} \; \
> > 		-exec grep -qF '/tmp' {} \; \
> > 		-print
> 
> 	This is the best solution.
> 
> -- 
> Steve O'Hara-Smith <steve@sohara.org>

One could change that last "grep" into

	-exec grep -lF '/tmp' {} +

... and drop the "-print".  That would make it more efficient, only
calling "grep" once on each file first, and then in bulk on the ones
that contain the first pattern.  If one knows what pattern is expected
to match the most files, that could be arranged to be the pattern used
in the first "grep" ("grep -q" is efficient and will terminate as soon
as the first match is found).

-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.



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