Date: Wed, 7 Sep 2022 20:10:21 -0400 From: "Kevin P. Neal" <kpn@neutralgood.org> To: Miguel C <miguelmclara@gmail.com> Cc: FreeBSD Mailing List <freebsd-questions@freebsd.org> Subject: Re: Slightly OT: How to grep for two different things in a file Message-ID: <Yxky7fDSqv%2B7vqyy@neutralgood.org> In-Reply-To: <CADGo8CW0=_j2zsC-Hryh8scaxZ-0Oxep9H0tY2DJm6RNzWZ5ug@mail.gmail.com> References: <CAGBxaXn6ZO-e0746fwzNp%2Bv-6bAucjxePMOt-mEv2HKmkCBXcg@mail.gmail.com> <YxkhieQ2omb3sr5s@harpo.local> <CADGo8CW0=_j2zsC-Hryh8scaxZ-0Oxep9H0tY2DJm6RNzWZ5ug@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Yxky7fDSqv%2B7vqyy>
