2014-02-26 42 views
0

我有一個實用程序(myexefile.exe),它輸出這樣的信息的列表:如何用.bat文件從輸出中刪除一行?

Line1=[Information in line1] 
Line2=[Information in line2] 
Line3=[Information in line3] 
Line4=[Information in line4] 
, etc. 

我用一個.bat文件,以將此信息寫入一個文本文件是這樣的:

set myexefile="c:\myexefile.exe" 
set outputfile="c:\outputfile.txt" 
%myexefile% >> %outputfile% 

但是,我想寫下所有行,除了爲包含「Line3 =」的行。

所以我想輸出到outputfile.txt是:

Line1=[Information in line1] 
Line2=[Information in line2] 
Line4=[Information in line4] 
, etc. 

我大概可以創建文件,因爲它然後使用一個現有的示例展示瞭如何從文本文件中刪除一行,但我寧願跳過這一行,而不是將其寫入文本文件,然後將其刪除。

有人可以幫助我嗎?

+0

對不起任何線,我應該更直接與這個問題。 .exe文件是C:\ WINDOWS \ system32 \ systeminfo.exe,我想從輸出中刪除包含「產品ID」的行。 – Trevor

回答

2
%myexefile% | find /v "Product ID">> %outputfile% 

應該過濾掉含產品ID

+0

感謝您的幫助。這就是我一直在尋找的。 – Trevor

0
setLocal enableDelayedExpansion 
set outputfile="c:\outputfile.txt" 
for /f "delims=" %%a in ('c:\myexefile.exe') do (
    set out=%%a 
    if "!out:~0,4!" NEQ "Line3" echo %%a>>%outputfile% 
) 

或備選地 -

set outputfile="c:\outputfile.txt" 
for /f "delims=" %%a in ('c:\myexefile.exe') do for /f %%b "delims=:" in ("%%a") do if "%%b" NEQ "Line3" echo %%a>>%outputfile% 
相關問題