Eti*_*nne 2 command-line cmd batch-file
下面的代码允许我使用命令行(CMD)在我的所有文件中找到"错误"一词.
find /c "error" C:\MyFiles\*.txt
Run Code Online (Sandbox Code Playgroud)
但我希望它同时寻找" 错误 "和" 警告 " 这个词.
所以我想将这两行放在一行命令中.
find /c "error" C:\MyFiles\*.txt
find /c "warning" C:\MyFiles\*.txt
Run Code Online (Sandbox Code Playgroud)
我不想看到2个结果集.
这应该工作(FINDSTR将搜索字符串拆分为空格,因此它会查找任一单词).
findstr "error warning" C:\MyFiles\*.txt
Run Code Online (Sandbox Code Playgroud)
应该这个等效的搜索:
findstr /c:"error" /c:"warning" C:\MyFiles\*.txt
Run Code Online (Sandbox Code Playgroud)
但是,有这个错误:为什么这个带有多个文字搜索字符串的FINDSTR示例找不到匹配?.我不确定上述搜索是否符合指定错误何时可能影响结果的标准.(我不确定搜索字符串之间是否有足够的重叠.)但最好是安全而不是抱歉.
您可以通过使搜索大小写不敏感来消除错误的可能性(不确定它是否符合您的要求):
findstr /i "error warning" C:\MyFiles\*.txt
Run Code Online (Sandbox Code Playgroud)
或者您可以将搜索字符串转换为正则表达式.在您的情况下实现这一点很简单,因为没有正则表达式元字符需要在搜索字符串中转义.
findstr /r "error warning" C:\MyFiles\*.txt
Run Code Online (Sandbox Code Playgroud)