Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Sep 2022 22:45:26 -0400
From:      grarpamp <grarpamp@gmail.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: Slightly OT: How to grep for two different things in a file
Message-ID:  <CAD2Ti29_f772xZx1qF-2%2B8SWpEdsnrHDO6-YFsSJgxOMEcLJyA@mail.gmail.com>
In-Reply-To: <CMQKET7J77ZC.JF6EL4PJ7K6N@eniac.local>
References:  <CAGBxaXn6ZO-e0746fwzNp%2Bv-6bAucjxePMOt-mEv2HKmkCBXcg@mail.gmail.com> <CMQKET7J77ZC.JF6EL4PJ7K6N@eniac.local>

next in thread | previous in thread | raw e-mail | index | archive | help
> awk '/pattern1/ {next} /pattern2/ {print FILENAME}' somefile.txt

If pat1 is not, but pat2 is, it will still print... undesired.

pcregrep will do multiline, but since you don't know
the appearance order or buffer distance, and if you may
not want to read the entire files off media twice, or wish
to keep execs down, etc... you may be left with using python
or perl or whatever else to check each lines for the pats,
set match flags, and when both set, print exit.

Guilty parties above will learn some better ways here...
https://www.idallen.com/topposting.html



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAD2Ti29_f772xZx1qF-2%2B8SWpEdsnrHDO6-YFsSJgxOMEcLJyA>