2017-06-20 79 views
0

当我使用find命令搜索字符串并打印字符串时,也会打印文件名。有没有办法避免打印文件名?在批处理脚本中使用'FIND'命令时避免打印文件名

对于防爆: 考虑一个文件Sample.log包含,

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

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

find " error " Sample.log >Result.txt 

中的Result.txt输出的电流

---------- .\Sample.log 
INF000005: <0> Error(s) and <0> Warning(s) detected. 
中的Result.txt

预计产量

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

回答

2

Simples:

find " error " <Sample.log >Result.txt 
+0

谢谢...它的工作非常好... –

0

最简单的方法就是管成more

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

“+2”因为find仍然会在头部之前打印出一个空行。

如果您希望发现超过65534个错误,则会有更多人中断脚本并提示输入以继续。

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

+1

'more'可能会挂起(等待用户的输入),当它接收到更多的65534行文字;也许你应该在你的答案中提到这个限制... – aschipfl

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

将避免该问题。 find说明你的文件名,因为它可能find在AFN串像*.txt

相关问题