为什么不使用多个文字搜索字符串FINDSTR这个例子找到一个匹配? [英] Why doesn't this FINDSTR example with multiple literal search strings find a match?
问题描述
下面的例子FINDSTR未能找到匹配。
The following FINDSTR example fails to find a match.
echo ffffaaa|findstr /l "ffffaaa faffaffddd"
为什么?
推荐答案
Apparantly这是一个长期FINDSTR错误。我觉得这可能是一个沉重的bug,视情况而定。
Apparantly this is a long standing FINDSTR bug. I think it can be a crippling bug, depending on the circumstances.
我已确认在两个不同的Vista计算机,Windows 7的机器,和XP的机器的命令失败。
我发现这个 FINDSTR - 破???一个报告链接Windows Server 2003上类似的搜索失败,但成功在Windows 2000上。
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
选项)
- The search is using multiple literal search strings
- The search strings are of different lengths
- A short search string has some amount of overlap with a longer search string
- The search is case sensitive (no
/I
option)
在每次我都看到失败,它始终是失败的较短的搜索字符串之一
In every failure I have seen, it is always one of the shorter search strings that fails.
不要紧,如何指定的搜索字符串。 搜索选项,同时用 / G:文件
选项相同的故障结果使用多个 / C ++实现
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.
唯一的解决方法3,我已经能够拿出有:
The only 3 workarounds I have been able to come up with are:
-
使用
/ I
如果你不关心的情况下的选择。显然,这可能不符合你的需求。
Use the
/I
option if you don't care about case. Obviously this might not meet your needs.
使用 / R
常规EX pression选项。但是,如果你这样做,那么你必须确保你逃避搜索的元字符,使其预期文字的搜索结果相匹配。这可能是有问题的为好。
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.
如果您使用的是 / V
选项,然后使用多个管道FINDSTR一个搜索字符串,而不是每一个FINDSTR多个搜索命令。这也可以是一个问题,如果你有很多的搜索字符串的您要使用 / G:文件
选项
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!!!!
注意的 - 请参阅什么是无证功能和限制在Windows FINDSTR命令?获得FINDSTR特质的COM prehensive列表。的
Note - See What are the undocumented features and limitations of the Windows FINDSTR command? for a comprehensive list of FINDSTR idiosyncrasies.
这篇关于为什么不使用多个文字搜索字符串FINDSTR这个例子找到一个匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!