From nobody Thu Sep 8 06:40:05 2022 X-Original-To: questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MNTyK50Y6z4cHnP for ; Thu, 8 Sep 2022 06:40:09 +0000 (UTC) (envelope-from andreas.kahari@abc.se) Received: from hekla.abc.se (hekla.abc.se [158.174.61.227]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA512) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4MNTyJ6wdpz3VW5 for ; Thu, 8 Sep 2022 06:40:08 +0000 (UTC) (envelope-from andreas.kahari@abc.se) Received: from harpo.local (83-233-37-250.cust.bredband2.com [83.233.37.250]) by hekla.abc.se (OpenSMTPD) with ESMTPSA id 60aed8e1 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 8 Sep 2022 08:40:06 +0200 (CEST) Date: Thu, 8 Sep 2022 08:40:05 +0200 From: Andreas Kusalananda =?utf-8?B?S8OkaMOkcmk=?= To: Steve O'Hara-Smith Cc: questions@freebsd.org Subject: Re: Slightly OT: How to grep for two different things in a file Message-ID: Mail-Followup-To: Steve O'Hara-Smith , questions@freebsd.org References: <20220908073350.2c16bf4e2c908c0ad007af3e@sohara.org> List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220908073350.2c16bf4e2c908c0ad007af3e@sohara.org> X-Rspamd-Queue-Id: 4MNTyJ6wdpz3VW5 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of andreas.kahari@abc.se designates 158.174.61.227 as permitted sender) smtp.mailfrom=andreas.kahari@abc.se X-Spamd-Result: default: False [-2.67 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; R_MIXED_CHARSET(0.62)[subject]; R_SPF_ALLOW(-0.20)[+ip4:158.174.61.227:c]; MIME_GOOD(-0.10)[text/plain]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:8473, ipnet:158.174.0.0/16, country:SE]; MLMMJ_DEST(0.00)[questions@freebsd.org]; RCPT_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; DMARC_NA(0.00)[abc.se]; RCVD_COUNT_TWO(0.00)[2]; ARC_NA(0.00)[] X-ThisMailContainsUnwantedMimeParts: N 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 wrote: > > > find src/java -type f \ > > -exec grep -qF 'tid' {} \; \ > > -exec grep -qF '/tmp' {} \; \ > > -print > > This is the best solution. > > -- > Steve O'Hara-Smith 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 .