Re: Slightly OT: How to grep for two different things in a file

From: Andreas Kusalananda Kähäri <andreas.kahari_at_abc.se>
Date: Thu, 08 Sep 2022 06:35:52 UTC
On Thu, Sep 08, 2022 at 07:31:16AM +0100, Steve O'Hara-Smith wrote:
> On Wed, 07 Sep 2022 20:43:21 -0700
> Carl Johnson <carlj@peak.org> 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.
> 
> -- 
> Steve O'Hara-Smith <steve@sohara.org>

It also fails if the inner "grep" returns a massive number of pathnames,
making the output "grep" command line too long.  Additionally, if the
inner "grep" does not return *anything*, the outer "grep" would try
reading its own standard input stream instead of any file.

-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.