JoJo said:
Folks:
I have 2 separate text file each containing a bunch of IP addresses.
The first text file (TextIP-1.txt) contains 100 IP addresses; list 1
below the other.
The second text file (TextIP-2.txt) contains 56 IP addresses; listed
1 below the other.
I am look for a script that would allow me to compare the content of
these 2 text files & identify those overlapping IP addresses that
exist in BOTH of these text files.
Maybe the results can be printed to a third text file. Any help
appreciated.
Since you are looking for IPs (as text lines) that are either common to both
or unique to either one or the other, I would use a pair of
Scripting.Dictionary objects as hash tables...
A simple demo...
'==================================================================
fileA = "c:\temp\TextIP-1.txt"
Set listA = CreateObject("Scripting.Dictionary")
listA.CompareMode = vbTextCompare
fileB = "c:\temp\TextIP-2.txt"
Set listB = CreateObject("Scripting.Dictionary")
listB.CompareMode = vbTextCompare
Set fso = CreateObject("Scripting.FileSystemObject")
with fso.OpenTextFile(fileA)
Do Until .AtEndOfStream
line = Trim(.ReadLine)
If Len(line) Then
listA(line) = True
wscript.echo line, "loaded in listA"
End If
Loop
.Close
End with
wscript.echo String(40,"-")
with fso.OpenTextFile(fileB)
Do Until .AtEndOfStream
line = Trim(.ReadLine)
If Len(line) Then
listB(line) = True
wscript.echo line, "loaded in listB"
End If
Loop
.Close
End with
'compare keys in listA with those in listB
wscript.echo String(40,"-")
For each key In listA.keys
If listB.Exists(key) Then
wscript.echo key, "in listA is in both lists"
Else
wscript.echo key, "in listA is not in listB"
End If
Next
'compare keys in listB with those in listA
wscript.echo String(40,"-")
For each key In listB.keys
If listA.Exists(key) Then
wscript.echo key, "in listB is in both lists"
Else
wscript.echo key, "in listB is not in listA"
End If
Next
'==================================================================
---------- cscript ----------
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
1.1.1.1 loaded in listA
2.2.2.2 loaded in listA
4.4.4.4 loaded in listA
5.5.5.5 loaded in listA
6.6.6.6 loaded in listA
8.8.8.8 loaded in listA
9.9.9.9 loaded in listA
----------------------------------------
1.1.1.1 loaded in listB
3.3.3.3 loaded in listB
5.5.5.5 loaded in listB
7.7.7.7 loaded in listB
9.9.9.9 loaded in listB
----------------------------------------
1.1.1.1 in listA is in both lists
2.2.2.2 in listA is not in listB
4.4.4.4 in listA is not in listB
5.5.5.5 in listA is in both lists
6.6.6.6 in listA is not in listB
8.8.8.8 in listA is not in listB
9.9.9.9 in listA is in both lists
----------------------------------------
1.1.1.1 in listB is in both lists
3.3.3.3 in listB is not in listA
5.5.5.5 in listB is in both lists
7.7.7.7 in listB is not in listA
9.9.9.9 in listB is in both lists
Output completed (0 sec consumed) - Normal Termination