Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried to find exact string from the file and increment the value of it. Content be like of file:

version=10
subversion=20


if I search version it increment the value of subversion.

What I have tried:

for /F "tokens=1,* delims==" %%i in ('findstr "version=  " file.ini') do (
	
    set "versionVar=%%~i"
    set "versionVal=%%~j"
    set  sequence=%%~j+1 
	)
	for /f "tokens=1,*delims=]" %%i in ('type "%file%" ^| find /v /n "" ^& break^>%file%') do (
    set "line=%%j"
    if "!line!" == "!versionVar!=!versionVal!" set line=!versionVar!=!sequence!
    echo(!line!>>!file!
	)
Posted
Updated 13-Nov-22 1:33am

1 solution

Variable expansion takes place before execution of the FOR command, so your script won't work.
For a solution see the answers here: how-to-set-a-variable-inside-a-loop-for-f[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900