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.
filename: Build.properties
label=12345
phase=test
*************************
i need to search label and replace value of it from 12345 to 5678
Please find the script
**************************************************************
(
FOR /f “usebackqdelims=” %%a IN (D:\Build.properties) DO (
FOR /f “tokens=1*delims==” %%g IN (“%%a”) DO (
IF /i “%%g”==”label” (ECHO(%%g
) ELSE (ECHO(%%a)
)
)
)>temp1.properties
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:\Build.properties) DO (
FOR /f “tokens=1* delims== ” %%g IN (“%%a”) DO (
IF /i “%%g%%h”==”label12345” (ECHO %%g=5678) else (echo %%a)
)
)
)>temp1.properties
message edited by nbrane