Loading ...
Sorry, an error occurred while loading the content.

[Clip] Re: Searching with Boolean Expressions

Expand Messages
  • diodeom
    ... 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 1 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")
    • flo.gehrke
      ... 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 2 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
      • John Shotsky
        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 3 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]
        • diodeom
          ... 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 4 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.
          • Art Kocsis
            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 5 of 14 , May 17, 2011
            • 0 Attachment
              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

              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.