Reputation: 7677
I have a simple text file with some tokens
This is ${token1} and this is ${token2}
And another file with token values like
token1=me
token2=my brother
I found a way to achieve this using java code and library called freemarker
I was wondering if its simple enough to do using batch commands?
Upvotes: 1
Views: 54
Reputation: 57272
With replacer.bat (it should be in the same directory as the script bellow):
@echo off
setlocal
set "textFile=C:\text.txt"
set "propertiesFile=C:\properties.txt"
for /f "usebackq tokens=1* delims==" %%a in ("%propertiesFile%") do (
call replacer.bat "%textFile%" "${%%a}" "%%b"
)
endlocal
with powershell :
@echo off
setlocal
set "textFile=C:\text.txt"
set "propertiesFile=C:\properties.txt"
for /f "usebackq tokens=1* delims==" %%a in ("%propertiesFile%") do (
powershell "(Get-Content '%textFile%') -replace '\$\{%%a\}', '%%b' | Set-Content '%textFile%'"
)
endlocal
Upvotes: 1