Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have 2 files
one is:
username date
A 2007-12-13
B 2007-12-18
C 2007-12-12another is:
username
A
B
C
D
E
FI want to compare these 2 files using ms-dos batch and give the result as below.
username date
A 2007-12-13
B 2007-12-18
C 2007-12-12
D
E
FI got stuck to figure out the solution. Thanks!

here's a vbscript
[code]
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set d = CreateObject("Scripting.Dictionary")
strFile1 = "c:\test\1.txt"
strFile2 = "c:\test\2.txt"
Set objFile1 = objFSO.OpenTextFile(strFile1,1)
Do Until objFile1.AtEndOfLine
strLine = objFile1.ReadLine
strArray1 = Split(strLine)
d.Add strArray1(0), strLine
Loop
Set objFile1 = Nothing
Set objFile2 = objFSO.OpenTextFile(strFile2,1)
Do Until objFile2.AtEndOfLine
strLine = objFile2.ReadLine
If d.Exists(strLine) Then
WScript.Echo d.Item(strLine)
Else
WScript.Echo strLine
End If
Loop
Set objFile2 = Nothing
Set objFSO = Nothing
[/code]

Thanks...
but i want to output the result as textfile also.
the code above give me a popup window for each line.

There was a similar question answered here about a couple of weeks ago. I can't remember the subject title, but I'm sure you'll find it if you search.
By the way, if you try to use ghostdog's suggestion you should run it with Cscript, not Wscript. CScript outputs lines to the console, and can be redirected to a file. Wscript, which you were using, outputs lines in a pop-up message box.

I got the output file, but I cannot get the 2nd column data in file 1. It only give me the same data as file 2.
Thank you~!

![]() |
VBS runs prog,display msg...
|
Saving the image in MS-Ac...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |