findstr 没有找到 "NOW"
findstr does not find "NOW"
我对 findstr 没有太多经验,但这对我来说根本无法理解。还是findstr的bug?
看看这些例子:
1) echo NOW|findstr "CLEAN NOCHANGE NOW">NUL&&echo found
return 没什么 但是为什么?
2) echo CLEAN|findstr "CLEAN NOCHANGE NOW">NUL&&echo found
return找到这里就可以了
3) echo NOCHANGE|findstr "CLEAN NOCHANGE NOW">NUL&&echo found
return 发现这也有效
但是当我使用 /I 时它有效
4) echo NOW|findstr /I "CLEAN NOCHANGE NOW">NUL&&echo found
-> return 发现没问题
如果 'now' 是小写 -> 它有效
5) echo now|findstr "CLEAN NOCHANGE now">NUL&&echo
找到
-> return 找到
字符串 "NOW" 有什么特别之处吗?
根据线程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?。
这是一个使用正则表达式搜索字符串的解决方法,因为没有使用元字符:
echo NOW| findstr /R "CLEAN NOCHANGE NOW" > nul && echo found
下面是对每个文字搜索字符串使用单独的 findstr
命令的解决方法:
echo NOW| (findstr /V "CLEAN" | findstr /V "NOCHANGE" | findstr /V "NOW") > nul || echo found
这是另一个基于 findstr
的小兄弟的解决方法,即 find
命令:
echo NOW| (find /V "CLEAN" | find /V "NOCHANGE" | find /V "NOW") > nul || echo found
我对 findstr 没有太多经验,但这对我来说根本无法理解。还是findstr的bug?
看看这些例子:
1) echo NOW|findstr "CLEAN NOCHANGE NOW">NUL&&echo found
return 没什么 但是为什么?
2) echo CLEAN|findstr "CLEAN NOCHANGE NOW">NUL&&echo found
return找到这里就可以了
3) echo NOCHANGE|findstr "CLEAN NOCHANGE NOW">NUL&&echo found
return 发现这也有效
但是当我使用 /I 时它有效
4) echo NOW|findstr /I "CLEAN NOCHANGE NOW">NUL&&echo found
-> return 发现没问题
如果 'now' 是小写 -> 它有效
5) echo now|findstr "CLEAN NOCHANGE now">NUL&&echo
找到
-> return 找到
字符串 "NOW" 有什么特别之处吗?
根据线程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?。
这是一个使用正则表达式搜索字符串的解决方法,因为没有使用元字符:
echo NOW| findstr /R "CLEAN NOCHANGE NOW" > nul && echo found
下面是对每个文字搜索字符串使用单独的 findstr
命令的解决方法:
echo NOW| (findstr /V "CLEAN" | findstr /V "NOCHANGE" | findstr /V "NOW") > nul || echo found
这是另一个基于 findstr
的小兄弟的解决方法,即 find
命令:
echo NOW| (find /V "CLEAN" | find /V "NOCHANGE" | find /V "NOW") > nul || echo found