From nobody Thu Sep 8 08:20:35 2022 X-Original-To: freebsd-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 4MNXBH2Vh5z4bWMF for ; Thu, 8 Sep 2022 08:20:39 +0000 (UTC) (envelope-from johnl@iecc.com) Received: from gal.iecc.com (gal.iecc.com [IPv6:2001:470:1f07:1126:0:43:6f73:7461]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "gal.iecc.com", Issuer "Let's Encrypt Authority X3" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MNXBG3zNbz3htF for ; Thu, 8 Sep 2022 08:20:38 +0000 (UTC) (envelope-from johnl@iecc.com) Received: (qmail 10816 invoked from network); 8 Sep 2022 08:20:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple; d=iecc.com; h=date:message-id:from:to:cc:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:cleverness; s=27d6.6319a5d5.k2209; bh=fdsaVhvLToim8R8gudSNK0YgH8qacMLXQUA0i3lmtBY=; b=d8LumQycw39Skn5XdDKOSAqBs/6MRvtnxJjbPCH+OrkkSJxGDdVNuDiYZgajNoND/cM9KuUW7VTX8JlO6j3KlHG3kp8Ub9rJrn7FZtJwkhTBTAUyyaEH5t4L85WCQ5RLkXKro62JfqPmIj8gwqzQYGHvw4kv2MlM6GcI9yRDR5TZZfj4IEr5Vts9SaWYPVkrgoQ2tBBuazKSm6kTEHuWwDgzqE8AJ41hZrPpZlnsLBWqbbLFMonAMWwHQE0ml5YSgmW3BEWgAw0pxEYYalm/8Uw8DaD+Tlqwn23KQsrWFKJr6h22czQu1EV68hFKjNXKp78dCqTgiTLrIb1j0+XZXg== Received: from ary.local ([IPv6:2001:470:1f07:1126::78:696d:6170]) by imap.iecc.com ([IPv6:2001:470:1f07:1126::78:696d:6170]) with ESMTPS (TLS1.3 ECDHE-RSA AES-256-GCM AEAD) via TCP6; 08 Sep 2022 08:20:37 -0000 Received: by ary.local (Postfix, from userid 501) id DD637492065F; Thu, 8 Sep 2022 10:20:35 +0200 (CEST) Date: 8 Sep 2022 10:20:35 +0200 Message-Id: <20220908082035.DD637492065F@ary.local> From: "John Levine" To: freebsd-questions@freebsd.org Cc: steve@sohara.org Subject: Re: Slightly OT: How to grep for two different things in a file In-Reply-To: <20220908073116.b95bf1b1495863241cc26248@sohara.org> Organization: Taughannock Networks X-Headerized: yes Cleverness: minimal 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-transfer-encoding: 8bit X-Rspamd-Queue-Id: 4MNXBG3zNbz3htF X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org; dkim=pass header.d=iecc.com header.s=27d6.6319a5d5.k2209 header.b=d8LumQyc; dmarc=pass (policy=none) header.from=iecc.com; spf=pass (mx1.freebsd.org: domain of johnl@iecc.com designates 2001:470:1f07:1126:0:43:6f73:7461 as permitted sender) smtp.mailfrom=johnl@iecc.com X-Spamd-Result: default: False [-6.40 / 15.00]; DWL_DNSWL_MED(-2.00)[iecc.com:dkim]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; RCVD_DKIM_ARC_DNSWL_MED(-0.50)[]; DMARC_POLICY_ALLOW(-0.50)[iecc.com,none]; MV_CASE(0.50)[]; RCVD_IN_DNSWL_MED(-0.40)[2001:470:1f07:1126:0:43:6f73:7461:from,2001:470:1f07:1126:0:78:696d:6170:received]; R_SPF_ALLOW(-0.20)[+ip6:2001:470:1f07:1126::/64]; R_DKIM_ALLOW(-0.20)[iecc.com:s=27d6.6319a5d5.k2209]; MIME_GOOD(-0.10)[text/plain]; DKIM_TRACE(0.00)[iecc.com:+]; FROM_EQ_ENVFROM(0.00)[]; MLMMJ_DEST(0.00)[freebsd-questions@freebsd.org]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; HAS_ORG_HEADER(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; TO_DN_NONE(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-ThisMailContainsUnwantedMimeParts: N It appears that Steve O'Hara-Smith said: >On Wed, 07 Sep 2022 20:43:21 -0700 >Carl Johnson wrote: > >> I use grep -l to just return a list of files that contain one pattern, >> and then grep -l for the second pattern on that list. That can be done >> in one line for your example as follows: >> >> grep -li /tmp `grep -liR tid src/java` > > This fails in the presence of filenames with spaces, which is a >pity because it is very elegant. Something like this should do it. The -print0 and -0 deal with spaces in the filenames, and the xargs handles more filenames than fit in a single command. $ find src/java -type f -exec grep -lq tid '{}' \; -print0 | xargs -0 grep -l /tmp -- Regards, John Levine, johnl@taugh.com, Primary Perpetrator of "The Internet for Dummies", Please consider the environment before reading this e-mail. https://jl.ly