在批处理脚本中使用"FIND"命令时避免打印文件名



当我使用 find 命令搜索字符串并打印字符串时,也会打印文件名。有没有办法避免打印文件名。

例如: 考虑一个文件示例.log其中包含,

INF000005: <0> Error(s) and <0> Warning(s) detected.   
INF000006: Execution completed successfully.

我使用以下命令运行批处理文件。

find " error " Sample.log >Result.txt

结果.txt 中的当前输出为

---------- .Sample.log  
INF000005: <0> Error(s) and <0> Warning(s) detected.

结果.txt 中的预期输出为

INF000005: <0> Error(s) and <0> Warning(s) detected

简单:

find " error " <Sample.log >Result.txt
type Sample.log | find " error "  >Result.txt

将避免该问题。find显示文件名,因为可以在 afn 中find字符串,例如*.txt

最简单的方法是将其传送到more

find " error " Sample.log|more +2 >Result.txt

"+2",因为 find 仍然在标题之前打印出一个空行。

如果预计发现超过 65534 个错误,则会中断脚本并提示输入以继续。

然而,Klitos Kyriacou提供的答案更可靠,甚至可能更简单。

最新更新