I have a file called "words.txt" that looks like this:
Code: Select all
[###]
one
two
three
A template.txt file that looks like:
Code: Select all
example [###]
The result should be :
Code: Select all
example one
example two
example three
The idea is: the code below walks through every line inside word.txt, it uses word.txt's first line as a replace string ([###] ) and then uses other lines (one, two, three) as replacements in template.txt
Code: Select all
@echo off
setLocal EnableDelayedExpansion
set /a counter=0
::go through words line by line
for /f "delims=" %%w in (words.txt) do (
set replace=%%w
if !counter! EQU 0 (
set search=%%w
)
if !counter! NEQ 0 (
::read template and replace !search! with !replace!
for /f "delims=" %%l in (template.txt) do (
set old=%%l
set new=!old:search=replace!
echo !new!
)
)
set /a counter+=1
)
echo !counter!
The current result that I see is:
Code: Select all
example [###]
example [###]
example [###]
... search and replace didn't work.
This is my first experience with DOS, and I would appreciate any help. (spent hours researching this, it should work but it doesn't, what am I missing?)
Thanks