• Search files (i.e. multiline text) for several strings - how?

    From Chris Green@3:633/10 to All on Friday, February 27, 2026 11:00:01
    I know and use grep extensively but this requirement doesn't quite fit
    grep.

    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.

    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 wild
    cards would suffice).

    Is there a tool out there that can do this?

    If not I can probably produce a bash script to do it using grep, i.e.
    use grep to get a list of files with the first word, grep that list of
    files for the second word, and so on. However if there's a ready made
    tool for doing it I'd like to know about it.

    --
    Chris Green
    ú

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Byunghee HWANG (???)@3:633/10 to All on Friday, February 27, 2026 12:00:01
    Hellow Chris,
    Chris Green <cl@isbd.net> writes:
    I know and use grep extensively but this requirement doesn't quite fit
    grep.

    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.

    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 wild
    cards would suffice).

    Is there a tool out there that can do this?

    If not I can probably produce a bash script to do it using grep, i.e.
    use grep to get a list of files with the first word, grep that list of
    files for the second word, and so on. However if there's a ready made
    tool for doing it I'd like to know about it.
    There is very simple way. You don't need any scripting or programming knowledge. See below: (file size is too big to send email with attach) <https://gitlab.com/soyeomul/Gnus/-/raw/d1c1a821330fec849c74813dab9c3d069be5940f/stuff/grep-gmail.png>

    Sincerely, Byunghee
    --
    ^????? _????_ ?????_^))//


    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris Green@3:633/10 to All on Friday, February 27, 2026 13:00:01
    Byunghee HWANG (???) <soyeomul@doraji.xyz> wrote:
    [-- text/plain, size 1.2K, charset utf-8, 35 lines, encoding quoted-printable --]

    Hellow Chris,

    Chris Green <cl@isbd.net> writes:

    I know and use grep extensively but this requirement doesn't quite fit grep.

    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.

    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 wild
    cards would suffice).

    Is there a tool out there that can do this?

    If not I can probably produce a bash script to do it using grep, i.e.
    use grep to get a list of files with the first word, grep that list of files for the second word, and so on. However if there's a ready made
    tool for doing it I'd like to know about it.

    There is very simple way. You don't need any scripting or programming knowledge. See below: (file size is too big to send email with attach) <https://gitlab.com/soyeomul/Gnus/-/raw/d1c1a821330fec849c74813dab9c3d069be5940f/stuff/grep-gmail.png>

    That's just an image of my message in Gmail, I can't work out where
    it's supposed to take me. I can get to the Gnus project in Gitlab but
    then couldn't find anything very relevant.

    N.B. the diary/journal entries are on my own system, not on the cloud
    anywhere.

    --
    Chris Green
    ú

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Greg Wooledge@3:633/10 to All on Friday, February 27, 2026 13:30:01
    On Fri, Feb 27, 2026 at 09:35:25 +0000, Chris Green wrote:
    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 wild
    cards would suffice).

    Is there a tool out there that can do this?

    https://mywiki.wooledge.org/BashFAQ/079

    I believe you want the section entitled

    foo AND bar in the same file, not necessarily on the same line

    although it's hard to be sure, because your problem description is
    somewhat unclear. (What is the format of a "journal entry"?)

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris Green@3:633/10 to All on Friday, February 27, 2026 16:00:01
    Greg Wooledge <greg@wooledge.org> wrote:
    On Fri, Feb 27, 2026 at 09:35:25 +0000, Chris Green wrote:
    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 wild
    cards would suffice).

    Is there a tool out there that can do this?

    https://mywiki.wooledge.org/BashFAQ/079

    I believe you want the section entitled

    foo AND bar in the same file, not necessarily on the same line

    although it's hard to be sure, because your problem description is
    somewhat unclear. (What is the format of a "journal entry"?)

    You have understood what I wanted. You've also shown me that,
    probably, rolling my own bash script to do it is the way to
    go. The solutions in the bashFAQ thread do much as I was suggesting
    when I asked the question.

    Thanks.

    --
    Chris Green
    ú

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From John Hasler@3:633/10 to All on Friday, February 27, 2026 16:30:01
    I'd use find with grep for that.
    --
    John Hasler
    john@sugarbit.com
    Elmwood, WI USA

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Lee@3:633/10 to All on Friday, February 27, 2026 23:10:01
    On Fri, Feb 27, 2026 at 4:50?AM Chris Green wrote:

    I know and use grep extensively but this requirement doesn't quite fit
    grep.

    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.

    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 wild
    cards would suffice).

    Is there a tool out there that can do this?

    AWK
    The trick being to set the record seperator (RS) to whatever delimits
    a single journal entry .. like a null line, so multiple lines are
    treated as a single record.
    for example

    $ cat journal.txt
    The green fox
    jumps over the
    red dog.

    The green fox
    jumped over the
    deep barrel full
    of water.

    The brown dog
    jumped over the
    deep barrle full
    of water.

    $ awk -v RS="" '/green/ && /water/ && /deep/ {print $0}' journal.txt
    The green fox
    jumped over the
    deep barrel full
    of water.

    Regards
    Lee

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Karl Vogel@3:633/10 to All on Sunday, March 01, 2026 00:30:01
    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

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Michael Paoli@3:633/10 to All on Sunday, March 01, 2026 22:00:02
    python, perl, sh, bash, awk, sed, ...
    $ < /usr/share/dict/words shuf | head -n 2
    smoothly
    launderer
    $ < /usr/share/dict/words perl -e '$a=0; $b=0; while(<>){if(! $a && /smoothly/){$a=1}; if(! $b && /launderer/){$b=1}; if($a && $b){ print
    "Found all by line $..\n"; exit;}}; print "Did not find all.\n";'
    Found all by line 85642.
    $ wc -l < /usr/share/dict/words
    104334
    $ < /usr/share/dict/words perl -e '$a=0; $b=0; while(<>){if(! $a && /smoXXXothly/){$a=1}; if(! $b && /launderer/){$b=1}; if($a && $b){
    print "Found all by line $..\n"; exit;}}; print "Did not find
    all.\n";'
    Did not find all.
    $

    On Fri, Feb 27, 2026 at 1:50?AM Chris Green <cl@isbd.net> wrote:

    I know and use grep extensively but this requirement doesn't quite fit
    grep.

    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.

    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 wild
    cards would suffice).

    Is there a tool out there that can do this?

    If not I can probably produce a bash script to do it using grep, i.e.
    use grep to get a list of files with the first word, grep that list of
    files for the second word, and so on. However if there's a ready made
    tool for doing it I'd like to know about it.

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)