Solved batch file property file string search and change the value

May 26, 2016 at 21:01:11
Specs: Windows 64
I have a batch file to search a string in a property file and after finding the string, replacing its value to anew value...This script was working fine since last month.Now it is doesnot working in any of the machines. i ran it in Windows 2008 server, windows 64 bit os everything.i checked antivirus too...but no issue found there.Can anyone help me to identify any code issue is there.


i need to search label and replace value of it from 12345 to 5678

Please find the script

FOR /f "usebackqdelims=" %%a IN (D:\ DO (
FOR /f "tokens=1*delims==" %%g IN ("%%a") DO (
IF /i "%%g"=="label" (ECHO(%%g
) ELSE (ECHO(%%a)

See More: batch file property file string search and change the value

Report •

May 27, 2016 at 11:37:45
✔ Best Answer
Mainly, there is no output of the replacement item:
IF /i "%%g"=="label" (ECHO(%%g

should be something like:
IF /i "%%g"=="label" (ECHO(%%g=5678

Secondly, you did not indicate whether you wanted to verify that the label value is "12345" before changing it. The above code replaces any value that is preceded by "label=", so if there is more than one "label=" instance, they will all be changed unconditionally to "5678". In case you intended to test the value this:
IF /i "%%g%%h"=="label12345" (ECHO(%%g=5678
However, no account is taken into for a space preceding the value. For that, you need to add space to the delimiters:

recap of code with modified structure:

FOR /f "usebackq delims=" %%a IN (D:\ DO (
FOR /f "tokens=1* delims== " %%g IN ("%%a") DO (
IF /i "%%g%%h"=="label12345" (ECHO %%g=5678) else (echo %%a)

message edited by nbrane

Report •
Related Solutions

Ask Question