2017-06-20 54 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