From nobody Thu Sep 8 00:10:21 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 4MNKJj1H6kz4bWQV for ; Thu, 8 Sep 2022 00:10:29 +0000 (UTC) (envelope-from kpn@neutralgood.org) Received: from gunsight1.neutralgood.org (gunsight1.neutralgood.org [IPv6:2607:f758:2280:1:d6be:d9ff:feac:a1e9]) (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 "gunsight1.neutralgood.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MNKJh3rBtz3mRq for ; Thu, 8 Sep 2022 00:10:28 +0000 (UTC) (envelope-from kpn@neutralgood.org) Received: from gunsight1.NeutralGood.ORG (localhost [127.0.0.1]) by gunsight1.neutralgood.org (8.16.1/8.15.2) with ESMTPS id 2880ALEf031162 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Wed, 7 Sep 2022 20:10:21 -0400 (EDT) (envelope-from kpn@gunsight1.NeutralGood.ORG) Received: (from kpn@localhost) by gunsight1.NeutralGood.ORG (8.16.1/8.15.2/Submit) id 2880ALW1031159; Wed, 7 Sep 2022 20:10:21 -0400 (EDT) (envelope-from kpn) Date: Wed, 7 Sep 2022 20:10:21 -0400 From: "Kevin P. Neal" To: Miguel C Cc: FreeBSD Mailing List Subject: Re: Slightly OT: How to grep for two different things in a file Message-ID: References: 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: X-No-archive: Yes X-Rspamd-Queue-Id: 4MNKJh3rBtz3mRq X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of kpn@neutralgood.org designates 2607:f758:2280:1:d6be:d9ff:feac:a1e9 as permitted sender) smtp.mailfrom=kpn@neutralgood.org X-Spamd-Result: default: False [-3.30 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; R_SPF_ALLOW(-0.20)[+mx]; MIME_GOOD(-0.10)[text/plain]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; ARC_NA(0.00)[]; ASN(0.00)[asn:13649, ipnet:2607:f758::/32, country:US]; MIME_TRACE(0.00)[0:+]; MLMMJ_DEST(0.00)[freebsd-questions@freebsd.org]; TO_DN_ALL(0.00)[]; RCVD_TLS_LAST(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; DMARC_NA(0.00)[neutralgood.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; MID_RHS_MATCH_FROM(0.00)[] X-ThisMailContainsUnwantedMimeParts: N On Thu, Sep 08, 2022 at 12:06:20AM +0100, Miguel C wrote: > Maybe I didn't understand the complexity here but doesn't grep -E or > egrep work here ? > egrep "string1|string2" ? > Also works with -r and you can use it inside exec in find too... but if > you want to search for more that one string AFAIK this is the easiest > way. This would give a success return code if either string is present in the input, but would not insist that both be present. So this won't do what Aryeh Friedman is requesting. Close, but not quite. > On Wed, Sep 7, 2022, 23:56 Andreas Kusalananda Kähäri > <[1]andreas.kahari@abc.se> wrote: > > On Wed, Sep 07, 2022 at 06:00:36PM -0400, Aryeh Friedman wrote: > > I have 2 patterns I need to find in a given set of files. A file > only > > matches if it contains *BOTH* patterns but not in any given > > relationship as to where they are in the file.  In the past I > have > > used piped greps when both patterns are on the same line but in my > > current case they are almost certainly not on the same line. > > > > For example my two patterns are "tid" (String variable name) and > > "/tmp" [String literal] (i.e. the full string is the concatenation > of > > the two patterns I would do: -- Kevin P. Neal http://www.pobox.com/~kpn/ "A pig's gotta fly." - Crimson Pig