Sometimes FINDSTR with multiple literal search strings fails to find all matches. For example, the following FINDSTR example fails to find a match.
echo ffffaaa|findstr /l "ffffaaa faffaffddd"
Why?
Apparantly this is a long standing FINDSTR bug. I think it can be a crippling bug, depending on the circumstances.
I have confirmed the command fails on two different Vista machines, a Windows 7 machine, and an XP machine. I found this findstr - broken ??? link that reports a similar search fails on Windows Server 2003, but it succeeds on Windows 2000.
I've done a number of experiments and it seems all of the following conditions must be met for the potential of a failure:
/I
option)In every failure I have seen, it is always one of the shorter search strings that fails.
It does not matter how the search strings are specified. The same faulty result is achieved using multiple /C:"search"
options and also with the /G:file
option.
The only 3 workarounds I have been able to come up with are:
Use the /I
option if you don't care about case. Obviously this might not meet your needs.
Use the /R
regular expression option. But if you do then you have to make sure you escape any meta-characters in the search so that it matches the result expected of a literal search. This can be problematic as well.
If you are using the /V
option, then use multiple piped FINDSTR commands with one search string each instead of one FINDSTR with multiple searches. This also can be a problem if you have a lot of search strings for which you want to use the /G:file
option.
I hate this bug!!!!
Note - See What are the undocumented features and limitations of the Windows FINDSTR command? for a comprehensive list of FINDSTR idiosyncrasies.