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

Re: Searching with Boolean Expressions

Expand Messages
  • flo.gehrke
    ... I have to add... A long aaaa... string is occurring in the two files that are being output (notetab.txt, pcre.txt). When moving those two files to
    Message 1 of 14 , May 17, 2011
      --- In ntb-clips@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
      >
      > This ends up in an empty document. Without the third line the
      > output is...
      >
      > notetab.txt: (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
      > pcre.txt: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
      > pcre.txt: (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()

      I have to add...

      A long 'aaaa...' string is occurring in the two files that are being output (notetab.txt, pcre.txt). When moving those two files to another directory the output is completely empty. That is, no one of those six files is being selected whereas my Agent Ransack clips provide correct results.

      Flo
    • diodeom
      ... Try placing at least a carriage return at each end of your sample content. Without a wholesome line to work on findstr aaaaa by itself produces
      Message 2 of 14 , May 17, 2011
        Flo wrote:
        >
        > Testing your clip I get no correct result. I created six short files (name / contents, using 'aaaaa' etc not to mix it up with other files in that directory):
        >
        > anthony.txt / aaaaa
        > bertha.txt / ooooo
        > carla.txt / bbbbb
        > elsa.txt / aaaaa ooooo
        > fred.txt / ooooo bbbbb
        > george.txt / aaaaa bbbbb
        >

        Try placing at least a carriage return at each end of your sample content. Without a wholesome line to work on findstr "aaaaa" by itself produces bunched-up results in one line (anthony.txt:aaaaaelsa.txt:aaaaa ooooogeorge.txt:aaaaa bbbbb). The subsequent findstr /v "ooooo bbbbb" attempts to locate a line that *does not* contain either "ooooo" or "bbbbb" -- and obviously fails.
      • Art Kocsis
        ... 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 3 of 14 , May 17, 2011
          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,
          >
          >Thanks for your pointing out FINDSTR and your clip!
          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

          Flo, the answer your question re exclusions is logical equivalences.

          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
        • 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 4 of 14 , May 17, 2011
            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 5 of 14 , May 17, 2011
              --- 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 6 of 14 , May 17, 2011
                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 7 of 14 , May 17, 2011
                  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 8 of 14 , May 17, 2011
                    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.