Login | |
|
 |
Re: Find the differences in two text files - 4/11/2005 5:44:43 AM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
load the contents of file one into a dictionary read in the second file (i prefer readlines) check to see if the name exists in the dictionary if so, continue the loop if not add to another dictionary output dictionary when its done reading the second file
|
|
| |
|
|
|
 |
Re: Find the differences in two text files - 4/11/2005 5:55:09 AM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
if not let me know, it should be pretty straight forward.
|
|
| |
|
|
|
 |
Re: Find the differences in two text files - 4/11/2005 6:07:39 AM
|
|
 |
|
| |
token
Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
|
There are a couple of ways to do this. In addition to what kirrilian suggested, I have another. This one has the benefits of having the big O to N*M[+N*M] as opposed to N^M (M being the number of files). ====================================================================== Option Explicit Dim fso, temp, hash, file1, file2, ts, hash2, key file1 = "F:\file1.txt" file2 = "F:\file2.txt" Set fso = CreateObject("Scripting.FileSystemObject") Set hash = CreateObject("Scripting.Dictionary") Set hash2 = CreateObject("Scripting.Dictionary") Set ts = fso.OpenTextFile(file1,1) Do Until ts.AtEndOfStream temp = ts.ReadLine hash.Item(temp) = 1 Loop ts.Close Set ts = fso.OpenTextFile(file2,1) Do Until ts.AtEndOfStream temp = ts.ReadLine If hash.Exists(temp) Then hash.Item(temp) = hash.Item(temp) + 1 Else hash.Item(temp) = 1 End If Loop For Each key In hash.Keys If hash(key) = 1 Then hash2(key) = True End If Next For Each key In hash2.Keys WScript.Echo key Next
|
|
| |
|
|
|
 |
Re: Find the differences in two text files - 4/11/2005 6:37:17 AM
|
|
 |
|
| |
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
|
quote: Originally posted by token The idea is pretty simple. Suppose you have 2 lists of names. When you add them into one big list, names that occur twice will exist in both smaller list while a name that exist only once are unique (exists in only one of the list). This unique name is then the DIFFERENCE between the 2 list of names. =)
good point
|
|
| |
|
|
|
|
|