## Re: [Clip] Re: Searching with Boolean Expressions

Expand Messages
• ... Ditto diodeom,. My development was interrupted at DOS and I was not even aware of FINDSTR. I have just used FIND and tried to work around its limitations.
Message 1 of 14 , May 17, 2011
• 0 Attachment
At 05/17/2011 04:29, you wrote:
>--- In <mailto:ntb-clips%40yahoogroups.com>ntb-clips@yahoogroups.com,
>"diodeom" <diomir@...> wrote:
> > Possibly for many tasks the good old findstr could be a
> > straightforward alternative...
>diodeom,
>
Ditto diodeom,. My development was interrupted at DOS and I was not even aware
of FINDSTR. I have just used FIND and tried to work around its limitations.
I really
need to spend some time looking over the XP commands!

>Moreover -- as far as I can see -- FINDSTR offers no Boolean NOT and no
>parentheses. So how could you define an exclusion like 'x NOT (y OR z)'?
>Flo

Your expression is actually: x AND (NOT (y OR z))

The logical equivalent of "NOT (y OR z)" is "(NOT y) AND (NOT z)" so your
expression becomes "x AND (NOT y) AND (NOT z)"

So to accomplish your expression use FINDSTR three times - once to
extract all "x"s, then to exclude all "y"s and finally to exclude all "z"s
piping the output each time to the next step. Each pipe is like an AND.

findstr x | findstr /v y | findstr /v z

Namaste', Art
• ... One can find lines not containing y s or z s in one shot by findstr /v y z where the space serves as OR in this notation. (By contrast, the following
Message 2 of 14 , May 17, 2011
• 0 Attachment
Art wrote:
>
> So to accomplish your expression use FINDSTR three times - once to
> extract all "x"s, then to exclude all "y"s and finally to exclude all "z"s
> piping the output each time to the next step. Each pipe is like an AND.
>
> findstr x | findstr /v y | findstr /v z
>

One can find lines not containing y's or z's in one shot by findstr /v "y z" where the space serves as OR in this notation. (By contrast, the following locates any lines without the literal "y z" string: findstr /v /c:"y z")
• ... diodeom, Yes, it s working with an additional CRNL. Also I can see the excluding effect now. May I tax your patience with another question? Does FINDSTR
Message 3 of 14 , May 17, 2011
• 0 Attachment
--- In ntb-clips@yahoogroups.com, "diodeom" <diomir@...> wrote:

> Try placing at least a carriage return at each end of your
> sample content.

diodeom,

Yes, it's working with an additional CRNL. Also I can see the excluding effect now.

May I tax your patience with another question? Does FINDSTR allow even more complex Boolean expressions? A next stage would be to add a third criterion and to exclude combined criteria. Given another file henry.txt...

aaaaa
bbbbb
ccccc

Now we want to find 'aaaaa' but exclude files containing 'bbbbb' and 'ccccc'. With Agent Ransack, it works with...

'aaaaa NOT (bbbbb AND ccccc)'

The correct output will be anthony.txt, elsa.txt, and george.txt.

Thanks also to Art Kocsis! Possibly, Art has explained this already but I can't see how to formulate it with FINDSTR.

So far, I didn't test it with a greater amount of files. But I'm sure that FINDSTR would be faster -- at least for simple evaluations. On the other hand, Agent Ransack might provide an easier solution.

Flo
• It s funny, I never thought much about Findstr before I learned regex. Now, when I see what all it can do, I think there are a lot of possibilities in my
Message 4 of 14 , May 17, 2011
• 0 Attachment
It's funny, I never thought much about Findstr before I learned regex. Now, when I see what all it can do, I think there
are a lot of possibilities in my clips. Here's Microsoft's reference page:

http://technet.microsoft.com/en-us/library/bb490907.aspx

Regards,

John

From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of diodeom
Sent: Tuesday, May 17, 2011 07:50
To: ntb-clips@yahoogroups.com
Subject: [Clip] Re: Searching with Boolean Expressions

Art wrote:
>
> So to accomplish your expression use FINDSTR three times - once to
> extract all "x"s, then to exclude all "y"s and finally to exclude all "z"s
> piping the output each time to the next step. Each pipe is like an AND.
>
> findstr x | findstr /v y | findstr /v z
>

One can find lines not containing y's or z's in one shot by findstr /v "y z" where the space serves as OR in this
notation. (By contrast, the following locates any lines without the literal "y z" string: findstr /v /c:"y z")

[Non-text portions of this message have been removed]
• ... Findstr operates in the context of individual lines within files, so to implement aaaaa NOT (bbbbb AND ccccc) for entire files, I d probably (at first
Message 5 of 14 , May 17, 2011
• 0 Attachment
Flo wrote:
>
> Now we want to find 'aaaaa' but exclude files containing 'bbbbb' and 'ccccc'. With Agent Ransack, it works with...
>
> 'aaaaa NOT (bbbbb AND ccccc)'
>

Findstr operates in the context of individual lines within files, so to implement "aaaaa NOT (bbbbb AND ccccc)" for entire files, I'd probably (at first glance) build the list of files containing "aaaaa" first:

findstr /m aaaaa

Then remove dupes, preserve the remnants for the last step and look among them for the first condition of exclusion:

findstr /m bbbbb

And then among the resulting list of files for the second condition:

findstr /m cccccc

Where I'd simply end up with any filenames to remove from the first list.

Achieving it with a single fancy long-winded call to cmd is probably not for the faint of heart, so I'd either make a .bat or just let Clip manipulate variables and act as glue between the blazing searches.

To answer your question, Flo, I don't see an AND provision within the Findstr itself, but command redirection operators (&, &&, | and ||) afford plenty of Boolean logic.
• Duh! I need more sleep. Or need to grow younger. I had just read that an hour earlier. In one eye and out the hole in my head!!! Art
Message 6 of 14 , May 17, 2011
• 0 Attachment
Duh! I need more sleep. Or need to grow younger.
In one eye and out the hole in my head!!!

Art

At 05/17/2011 07:49, diodeom wrote:
>Art wrote:
> > So to accomplish your expression use FINDSTR three times - once to
> > extract all "x"s, then to exclude all "y"s and finally to exclude all "z"s
> > piping the output each time to the next step. Each pipe is like an AND.
> >
> > findstr x | findstr /v y | findstr /v z
>
>One can find lines not containing y's or z's in one shot by findstr /v "y
>z" where the space serves as OR in this notation. (By contrast, the
>following locates any lines without the literal "y z" string: findstr /v
>/c:"y z")
Your message has been successfully submitted and would be delivered to recipients shortly.