Batch script to modify .properties file -
this question has answer here:
i have properties file (server.properties) , looks this:
ipaddress=10.x.x.x
servername=somename
and lot of other values.
let's located @ c:\server\server.properties
there way modify values using batch script.
what if want change servername "somename" "myname" ? can't use line numbers because can change anytime.
this not duplicate of how can find , replace text in file using windows command-line environment?
i trying figure out how replace value of property. not replacing 1 word another.
thanks.
@echo off setlocal set "sourcedir=c:\106x" ( /f "usebackqdelims=" %%a in ("%sourcedir%\q25967146.txt") ( /f "tokens=1*delims==" %%g in ("%%a") ( if /i "%%g"=="servername" (echo(%%g=%~1 ) else (echo(%%a) ) ) )>newfile.txt :: newfile.txt contains modified version. :: line overwrite original echo(move /y newfile.txt "%sourcedir%\q25967146.txt" goto :eof
you need change setting of sourcedir
suit circumstances.
i used file named q25967146.txt
containing data testing. change name suit yourself.
produces newfile.txt
the required move commands merely echo
ed testing purposes. after you've verified commands correct, change echo(move
move
move files. append >nul
suppress report messages (eg. 1 file moved
)
the method shown above deliberately creates new file in order new version can viewed without damaging original.
note version remove empty lines file when creating new version. can overcome if required.
to run routine, use
thisbatchname "replacement text"
if replacement text single string without spaces or other separators (as seems likely) quotes can omitted.
code fixed - there delims=="
in for /f...%%a...
line, should delims=
(one =
.) double =
correct in for /f ... %%g...
line.
to replace file, activate move
instructed replacing echo(move
move
- once you've verified procedure operating correctly. you've seen, 1 small error , damage have been done - saved two-step operation.
Comments
Post a Comment