开发者

Create output file using input data by batch file

开发者 https://www.devze.com 2023-02-04 22:24 出处:网络
I have data text file (include 42 lines) and batch file that read in each iteration 3 lines from the data file, process them, and type the output to output file, and then read following 3 line etc.

I have data text file (include 42 lines) and batch file that read in each iteration 3 lines from the data file, process them, and type the output to output file, and then read following 3 line etc.

It's seems like that:

ECHO OFF
cls

setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (data.txt) do (
set /a N+=1
set v!N!=%%a

)

set iteration=1
set /a eod=%N%/3-1

:start

if %iteration%==1 goto 1
if %iteration%==2 goto 2
.
.

:1
ECHO iteration %iteration% >> output.txt
set sn=!v1!
set s=!v2!
set d=!v3!
goto e

:2
ECHO iteration 开发者_Go百科%iteration% >> output.txt
set sn=!v4!
set s=!v5!
set d=!v6!
goto e
.
.

I want to ask if it's possible to use variable so I can abstain duplication code in the lines : set sn=!v1! and instead of this to write somethings like : set sn=!vN!

Thanks Rina


You can try this.

@echo off
SETLOCAL EnableDelayedExpansion
set n=0
for /F "delims=" %%a in (cn.txt) do (
    set /a n+=1
    set "v!n!=%%a"
)

call :GetThreePack 1
echo sn=!sn!
echo  s=!s!
echo  d=!d!
goto :eof

:GetThreePack 
set /a n=3*%1 + 1
set "sn=!v%n%!"

set /a n+=1
set "s=!v%n%!"

set /a n+=1
set "d=!v%n%!"
goto :eof
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号