I am trying to automate adding a certain line of text into a text file. For example, adding this line "Script#3=script3" under the last row of the "~block 2~" paragraph. However, the amount of items in the "~block 2~" paragraph may vary.
"~block 1~"
Script#1=script1
Script#2=script2
"~block 2~"
Script#1=script1
Script#2=script2
"~block 3~"
Script#1=script1
Script#2=script2
TO
"~block 1~"
Script#1=script1
Script#2=script2
"~block 2~"
Script#1=script1
Script#2=script2
Script#3=script3
"~block 3~"
Script#1=script1
Script#2=script2
I have tried writing the code but it does not seem to be working.
@echo OFF
SET /A CHECK = 0
SET /A a = 1
(
FOR /F "tokens=*" %%A IN (C:\Users\Desktop\testBatchtestModify.txt) DO (
ECHO %%A
IF %CHECK%==0 (
ECHO %%A
)
ELSE (
IF "%%A" EQU "" (
ECHO "Script#" %CHECK% "=TEST"
ECHO
SET /A CHECK = 0
)
ELSE (
SET /A CHECK = %CHECK%+%a%
ECHO %%A
)
)
IF "%%A" EQU "~block 2~" (
SET /A CHECK = 1
)
) >> temp.txt
move /y temp.txt C:\Users\Desktop\testBatchtestModify.txt