0

I need to run a process on many items and the process takes a configuration file as input. The configuration file needs to be changed for each item at three different lines (1,2,17) with different extensions. I can read the configuration file into batch script as a text file but it should be saved with *.cfg configuration so that it can be used. I have put together the following pseudo code with pointers where I would need help for making it functioning batch script.

set inputline=1
set outputline=2
set xmlline=17
set infile=config.txt
set items=list.txt


for /f "delims=" %%a in (%items%) do (
echo.%%a

set curr=1
for /f "delims=" %%b in (%infile%) do (

     if !curr!==%inputline%  [replace this line in infile with "a".ext1]
     if !curr!==%outputline%  [replace this line in infile with "a".ext2]
     if !curr!==%xmlline%  [replace this line in infile with "a".ext3]
)
 set /b "curr = curr + 1"
 [save "infile".cfg]


)
 "call" proccess.exe -config.cfg 
)

And the configuration file:

sample.264            
sample.yuv            
test_rec.yuv             
1                       
1                       
0                       
2                        
500000                   
104000                   
73000                   
leakybucketparam.cfg     
1                        
2                       
2                        
0                       
1                        
sample.xml            
3   
Mark
  • 3,609
  • 1
  • 22
  • 33
Martin
  • 3
  • 2

2 Answers2

0

Batch has no built in way of replacing a single line in a text file - however you can read the entire contents of the file, change the lines, then rewrite the file.

set file=config.txt

setLocal enableDelayedExpansion
set count=0

for /F "delims=~!" %%b in ('type %file%') do (
    set /a count=!count!+1
    set line!count!=%%b
)

set line1="a".ext1
set line2="a".ext2
set line17="a".ext3

del %file%
for /L %%c in (1,1,!count!) do echo !line%%c!>>%file%

pause

I slightly modified what I did here. I took out the check to see if the file exists, as you should be able to assume that it will.

Community
  • 1
  • 1
unclemeat
  • 5,029
  • 5
  • 28
  • 52
0

Thanks unclemeat, it helped me to nail-down the following working code for me:

set file=config.cfg
set vdos=test.txt

setlocal enabledelayedexpansion

for /f "delims=" %%a in (%vdos%) do (
echo %%a

set count=0
for /F "delims=~!" %%b in ('type %file%') do (
set /a count=!count!+1
set line!count!=%%b
)

set line1=%%a%.264
set line2=%%a%.yuv
set line17=%%a%.xml
del %file%
for /L %%c in (1,1,!count!) do echo !line%%c!>>%file%
ldecod config.cfg
)
Martin
  • 3
  • 2