updating text file using a batch sc

February 17, 2009 at 06:49:00
Specs: Windows 2000
I need your help with this.

I am trying to write a batch file to replace a line in one text file with a line from another text file.

Say
TextA has these lines:
line1
line2
line3
and TextB has the following
line4
line5
line6
So I would like to replace line3 in TextA with line6 from TextB.

Thanks
Al


See More: updating text file using a batch sc

Report •


#1
February 19, 2009 at 16:02:24
@echo off > newfile & setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (textb) do (
set str=%%a
)

for /f "tokens=* delims= " %%i in (texta) do (
set /a N+=1
if !N! equ 3 (
echo !str! >> newfile
) else (
echo %%i >> newfile
)
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
February 20, 2009 at 13:18:44
Thanks. I have not tried it to see if it works. I let you know in a day or two.
ALK

Report •

#3
February 20, 2009 at 15:06:43
It does not work the way you wanted. The batch is just appending the line6 from textB to textA.

I want the batch file to replace line3 of the textA by line6 of textB.

If VB script could get done that will be great.

Thanks.


Report •

Related Solutions

#4
February 21, 2009 at 02:53:01
It works here. Anybody's guess why not there.


=====================================
If at first you don't succeed, you're about average.

M2


Report •


Ask Question