>> On Fri 27 Feb 2026 at 04:50:42 (-0500), Chris Green wrote:

> I want to search lots of diary/journal entries (which are just plain
> text files) for entries which have two or more specified strings in
> them.

"ugrep" will do what you want.  If you want to stick with regular grep,
you can do an "OR" match with a one-liner (not what you asked) but a script
or function would be needed for "AND".

Test files

  me% ls -l
  -rw-r--r-- 1 vogelke mis  77 28-Feb-2026 17:43:21 a
  -rw-r--r-- 1 vogelke mis 143 28-Feb-2026 17:43:26 b
  -rw-r--r-- 1 vogelke mis 224 28-Feb-2026 17:43:36 c
  -rw-r--r-- 1 vogelke mis  90 28-Feb-2026 17:43:42 d

  me% head *
  ==> a <==
  I know and use grep extensively but this requirement doesn't quite
  fit grep.

  ==> b <==
  I want to search lots of diary/journal entries (which are just
  plain text files) for entries which have two or more specified
  strings in them.

  ==> c <==
  E.g.  I'm looking for journal entries which have, say, the words 'green',
  'water' and 'deep' in them.  Ideally the strings searched for could be
  Regular Expressions (though simple command line type wildcards would
  suffice).

  ==> d <==
  Is there a tool out there that can do this?  Include the word
  'Green' to allow one match.

UGREP

  me% ugrep --files --bool 'green AND water AND deep' *
  c
   1: E.g.  I'm looking for journal entries which have, say, the words 'green',
   2: 'water' and 'deep' in them.  Ideally the strings searched for could be

  me% ugrep -l --files --bool 'green AND water AND deep' *
  c

OR match

  me% grep -Eil 'green|water|deep' *
  c
  d

AND match

  me% grep -li green * | xargs grep -li water | xargs grep -li deep
  c

-- 
Karl Vogel                      I don't speak for anyone but myself

Congratulations on your promotion.  Before you go, would you like to take
this knife out of my back?  You'll probably need it again.
                                            --rejected Hallmark Cards

Reply via email to