Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 通过在项目的输入文件中循环来编辑文本文件的特定行_Batch File - Fatal编程技术网

Batch file 通过在项目的输入文件中循环来编辑文本文件的特定行

Batch file 通过在项目的输入文件中循环来编辑文本文件的特定行,batch-file,Batch File,我需要在许多项目上运行一个进程,该进程将配置文件作为输入。每个项目的配置文件都需要在三个不同的行(1、2、17)上更改,并具有不同的扩展名。我可以将配置文件作为文本文件读取到批处理脚本中,但它应该与*.cfg configuration一起保存,以便使用。我已经把下面的伪代码和指针放在一起,在这里我需要帮助才能使它运行批处理脚本 set inputline=1 set outputline=2 set xmlline=17 set infile=config.txt set items=list

我需要在许多项目上运行一个进程,该进程将配置文件作为输入。每个项目的配置文件都需要在三个不同的行(1、2、17)上更改,并具有不同的扩展名。我可以将配置文件作为文本文件读取到批处理脚本中,但它应该与*.cfg configuration一起保存,以便使用。我已经把下面的伪代码和指针放在一起,在这里我需要帮助才能使它运行批处理脚本

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 
)
和配置文件:

sample.264            
sample.yuv            
test_rec.yuv             
1                       
1                       
0                       
2                        
500000                   
104000                   
73000                   
leakybucketparam.cfg     
1                        
2                       
2                        
0                       
1                        
sample.xml            
3   

Batch没有内置的方法来替换文本文件中的一行,但是您可以读取文件的全部内容,更改行,然后重写文件

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

我稍微修改了一下我的做法。我进行了检查以查看文件是否存在,因为您应该能够假设它会存在。

谢谢,它帮助我确定了以下工作代码:

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
)

显示您的配置文件。