2

I don't have a lot of experiences with findstr but this is not understandable for me at all. Or is it a bug of findstr?

look at these examples:

1) echo NOW|findstr "CLEAN NOCHANGE NOW">NUL&&echo found return nothing But why??

2) echo CLEAN|findstr "CLEAN NOCHANGE NOW">NUL&&echo found return found here it's ok

3) echo NOCHANGE|findstr "CLEAN NOCHANGE NOW">NUL&&echo found return found this also work

But when I use /I it works
4) echo NOW|findstr /I "CLEAN NOCHANGE NOW">NUL&&echo found -> return found its ok

if 'now' is lowercase -> it works
5) echo now|findstr "CLEAN NOCHANGE now">NUL&&echo found -> return found

Is there something special with string "NOW" ?

laza
  • 91
  • 7
  • 1
    There is nothing special with `NOW`, but there is [much special about findstr](http://stackoverflow.com/questions/8844868/what-are-the-undocumented-features-and-limitations-of-the-windows-findstr-comman) (it's a microsoft tool) – jeb May 12 '17 at 08:45

1 Answers1

1

According to the thread Why doesn't this FINDSTR example with multiple literal search strings find a match?, findstr does not behave correctly when having multiple literal case-sensitive search strings, which are of different lengths and partially overlapping. Reference also this post: What are the undocumented features and limitations of the Windows FINDSTR command?.

Here is a work-around using regular expression search strings as no meta characters are used:

echo NOW| findstr /R "CLEAN NOCHANGE NOW" > nul && echo found

Here is a work-around using individual findstr commands for every single literal search string:

echo NOW| (findstr /V "CLEAN" | findstr /V "NOCHANGE" | findstr /V "NOW") > nul || echo found

Here is another work-around based on the small sibling of findstr, namely the find command:

echo NOW| (find /V "CLEAN" | find /V "NOCHANGE" | find /V "NOW") > nul || echo found
Community
  • 1
  • 1
aschipfl
  • 33,626
  • 12
  • 54
  • 99