Sorry for the very simplified version of my question but I'll figure from here.
I have a text file containing one word each line.
Peter
Tommy
Mike
I have another file containing a text.
Hello %VARIABLE%
How are you doing?
I'd like to have a batch file that creates one new text file for each line from the first text file and name them accordingly.
Peter.txt:
Hello Peter
How are you doing?
Tommy.txt:
Hello Tommy
How are you doing?
Mike.txt:
Hello Mike
How are you doing?
Here is where I am now.
@echo off
for /f "delims=" %%x in (file.txt) do set /p nAme=%%x
(
echo Hello %nAme%
echo.
echo How are you doing?
)>%nAme%.txt
This (test.bat) only writes the variables on screen, and creates a test.txt file with
Hello test
How are you doing?
CodePudding user response:
A FOR command with the /F option is used to read a file.
FOR /F "usebackq delims=" %%G IN ("file.txt") DO (
echo Hello %%G>"%%G.txt"
echo How are you doing?>>"%%G.txt"
)