Batch file 批处理文件批处理脚本中的子字符串替换

Batch file 批处理文件批处理脚本中的子字符串替换,batch-file,scripting,Batch File,Scripting,您好,我正在尝试使用batchscript替换文本文件的内容 setlocal enableextensions enabledelayedexpansion set line=0 set position=0 set replacetoken=POSITION set newfile = new.txt for /f "tokens=* delims=" %%x in (resproprty.txt) do ( @echo off set /a line+=1 if not !line!=

您好,我正在尝试使用batchscript替换文本文件的内容

setlocal enableextensions enabledelayedexpansion
set line=0
set position=0
set replacetoken=POSITION
set newfile = new.txt
for /f "tokens=* delims=" %%x in (resproprty.txt)  do  (
@echo off
set /a line+=1
if not !line!==1 (
set /a position+=1
)
set newcount=0
set newcount=!position!
set content=%%x
echo !content!
set content=!content:%replacetoken%=POSITION@!position!!
echo !newcount!
echo !position!
@echo on
echo !content! >> NEW.TXT
)
set test=Hello!
echo %test%
endlocal
在这里,我试图用
POSITION@1
POSITION@number
正在递增。但是它不起作用!位置!没有给出任何输出,我甚至尝试了
%position%
,但只给出了0的输出。请帮助

像这样尝试:

@echo off
if exist output.txt del output.txt
setlocal EnableDelayedExpansion
set /a $count=1
for /f "delims=" %%a in ('type "resproprty.txt"') do (
set line=%%a
call set line=!line:POSITION=POSITION@%%$count%%!
echo !line!>>output.txt
set /a $count+=1
)

Echo ok
这将创建文件
output.txt
,更改完成后

@ECHO关闭
SETLOCAL ENABLEDELAYEDEXPANSION
(
对于/f“tokens=1*delims=:”%%a IN('findstr/n/r.“.q22988413.txt”)DO(
设置“行=%%b”
设置“行=!行:位置=位置@%%a!”
回声(!线!
)
)>newfile.txt
后藤:EOF
我使用了一个名为
q22988413.txt的文件,其中包含

Hello position one
Hello position two
Hello position three
Hello position four
Hello position five
newfile.txt

Hello position@1 one
Hello position@2 two
Hello position@3 three
Hello position@4 four
Hello position@5 five