Batch script fot replacing a word in txt

October 12, 2010 at 08:09:18
Specs: Windows 7, Q9550 / 4 Gig
Hi,

I have a txt with one line: blah blah NAME blah PLACE blah

and another with a list of names:
name1
name2
name2
name3
........

I want a batch that will make a new txt which should look like:

blah blah name1 blah placeX blah
blah blah name2 blah placeX blah
blah blah name2 blah placeX blah
blah blah name3 blah placeX blah
.................................................

New file should have the line of the first txt, NAME replaced by name1, 2. 3..... and PLACE by placeX. The new file must have so many lines as the number of names of the list. Some names maybe the same but every one has in it's own line in the list. PLACE will be the same placeX for all names.

Thanks a lot for any help.


See More: Batch script fot replacing a word in txt

Report •


#1
October 12, 2010 at 12:23:01
@echo off & setlocal EnableDelayedExpansion > Names.new
set /P Line=< Line.txt
set Line=%Line:PLACE=placeX%
for /F "delims=" %%j in (Names.txt) do (
  set Row=!Line:NAME=%%j!
  echo.!Row!>> Names.new
)


Report •

#2
October 12, 2010 at 14:13:50
Excellent! That's exactly what I need, thank you very much!

Report •
Related Solutions


Ask Question