2016-01-06 75 views
0

假設我有這樣的批處理腳本:讀取線之後每隔一行讀

node1.log  
node2.log 
node3.log 
node4.log etc... 

我想逐行讀取每一行並執行一個文本文件,執行命令

alan.exe node1.log node2.log 
alan.exe node3.log node4.log 

等..

完成此操作的最佳方法是什麼?

+0

請注意,'DOS'是從上世紀80年代年/ 90操作系統!請改用標籤Windows。代碼正常。 – SteveFest

回答

0

試試這個。 File.txt將會有你的日誌文件名。

@echo off 
setlocal enabledelayedexpansion 

FOR /F "delims=" %%G IN ('find /c /v "" ^<file.txt') DO SET NUM=%%G 

SET /A NUM=NUM/2 

< file.txt (
    FOR /L %%G IN (1,1,%NUM%) DO (
     SET /P LINE1= 
     SET /P LINE2= 
     echo mypgm.exe !LINE1! !LINE2! 
    ) 
) 
pause 

輸出

mypgm.exe node1.log node2.log 
mypgm.exe node3.log node4.log 
mypgm.exe node5.log node6.log 
Press any key to continue . . . 

刪除單詞回聲和你想運行的程序替換mypgm.exe。回聲只是在那裏爲了概念的證明。

+0

嗨,squashman代碼工作。謝謝您的幫助 – apurva

0

像這樣:

@echo off 

setlocal enabledelayedexpansion 
set args= 
set n=2 
for /f "tokens=*" %%x in (file.txt) do (
    set args=!args! %%x 
    set /a n -= 1 
    if !n! EQU 0 (
     alan !args! 
     set args= 
     set n=2 
    ) 
) 
1
@echo off 
setlocal EnableDelayedExpansion 

for /F "delims=" %%a in (file.txt) do (
    if not defined line (
     set "line=%%a" 
    ) else (
     ECHO alan.exe !line! %%a 
     set "line=" 
    ) 
) 
相關問題