read simultialy from two files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
yossibr
Posts: 2
Joined: 12 Jul 2009 03:35

read simultialy from two files

#1 Post by yossibr » 12 Jul 2009 03:44

Hi ta all,

I need
to read simultialy from two files

example :
one from par1 and one from par2

for /f %%i in (par1 ) do (
echo ------ %%i ------
)

for /f %%z in (par2) do (
echo ++++++ %%z ++++++
)

thanks .

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

#2 Post by ghostmachine4 » 12 Jul 2009 05:16

assuming your files are of the same number of lines, here's a vbscript

Code: Select all

Set objFS = CreateObject("Scripting.FileSystemObject")
strFile1 = "c:\test\file.txt"
strFile2 = "c:\test\file2.txt"
Set objFile1 = objFS.OpenTextFile(strFile1)
Set objFile2 = objFS.OpenTextFile(strFile2)
Do Until objFile1.AtEndOfLine
   strLine1 = objFile1.ReadLine
   strLine2 = objFile2.ReadLine
   WScript.Echo strLine1 & "->" & strLine2
Loop
objFile1.Close
objFile2.Close


output

Code: Select all

C:\test>more file1.txt
1
2
3
4

C:\test>more file2.txt
a
b
c
d

C:\test>cscript /nologo test.vbs
1->a
2->b
3->c
4->d


yossibr
Posts: 2
Joined: 12 Jul 2009 03:35

#3 Post by yossibr » 12 Jul 2009 05:21

ghostmachine4 , thank tou for your quick answer .
This script must br run under dos command only .

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#4 Post by avery_larry » 14 Jul 2009 11:53

What do you want to do? Output alternating lines from the 2 files? Jumble the output together in whatever order happens?

Post Reply