VBScript: compare 2 csv files and only output differences
Posted on 2009-02-17
I picked up a scripting issue to try and compare 2 csv files and only output differences.
One file is created using a command line invoking 'AD.EXE' which outputs to csv. The 2nd using vbscript, basically formats the raw data into a more readable context, also into csv.
I want to be able to just run the 1st command again and compare the output to the constant unaltered 2nd csv and only output the differences, these being additional servers that have since been added to the domains.
The script breaks 'line 45, char 17 - type mismatch 800A00D'. Please, has anybody any ideas on how I might achieve my objective?
'On Error Resume Next
Dim DomInput, objFso, objFile0, oDomain, objFile, objFile1, sInput, sResults, strLine1, strLine2, strMatch, x, y, z0
Const ForReading = 1, ForWriting = 2
DomInput = ("Domains.txt")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile0 = objFSO.OpenTextFile(DomInput,1)
Do Until objFile0.AtEndOfStream
oDomain = objFile0.readline
sInput = (oDomain&".csv")
sResults = (oDomain&"Results.csv")
Set objFile = objFSO.OpenTextFile(sInput,1)
Set objFile1 = objFSO.OpenTextFile(sResults,1)
Do Until objFile.AtEndOfStream
x = objFile.readline
if left(x,2)="dn" then
y = split(x,",")
z0 = split(y(0),"=")
'strMatch = False
strLine1 = z0
Do Until objFile1.AtEndOfStream
strLine2 = objFile1.Readline
If Trim(UCase(strLine2))= strLine1 Then
strMatch = True
If strMatch <> True then
Wscript.Echo "Job Done!"
I need my script to