Reputation: 129
I've got to create a text file for each PC at my workplace is there a way to have a batch read from a list of PCs in a text file and create a text file for each line of text?
Ex. Text File
Computer1
Computer2
Computer3
I want it to create a computer1.txt, computer2.txt, and computer3.txt, but for a list of about 400 PCs... It seems pretty easy I'm just not sure how to link batch files together. I'm learning! :) Thanks for all your help, as always!
Upvotes: 1
Views: 8050
Reputation: 5204
I had a similar but different requirement, which was that my file had two columns of data, comma separated.
First col: the file name I wanted
Second col: the data for the contents of that file (HTML)
i.e.:
asdf.html, <p>Text about this</p>
bcvadf.html, <p>More text</p>
So this was what I put in cmd:
FOR /F "tokens=1,2 delims=," %G in (file.csv) DO echo %H > D:\temp\%G
Explanation:
Further understanding and examples, as in crownedzero's answer, https://ss64.com/nt/for_f.html
Upvotes: 0
Reputation: 7095
@echo off
setlocal
for /f "tokens=*" %%a in (comps.txt) do (type nul>"%%a.txt")
To add a pre-defined text to the file, do something like this:
for /f "tokens=*" %%a in (comps.txt) do (
echo This is line 1 of text>"%%a.txt"
echo This is line 2 of text>>"%%a.txt"
echo This is line 3 of text>>"%%a.txt"
echo This is line 4 of text>>"%%a.txt"
)
Upvotes: 5
Reputation: 506
FOR /F ["options"] %%parameter IN (filenameset) DO command
See also: Batch script to read input text file and make text file for each line of input text file
Upvotes: 0