0

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?

1 Answer 1

1

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"
)
Sign up to request clarification or add additional context in comments.

1 Comment

thanks it's great! oh man i was so close :) little mod for me because the real file is a 100+ line ps1 script, is that i only put )>>"%%G.txt" at the end not after every line. thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.