[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3825
  • Last Modified:

VBScript: compare 2 csv files and only output differences

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?

Option Explicit
'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
                End If
            Loop

        If strMatch <> True then
           objNewServers_forPatching.writeline strLine1
        End If

SInput.Close
sResults.Close
Wscript.Echo "Job Done!"
       End If
    Loop
Loop



I need my script to
0
jahogan
Asked:
jahogan
  • 3
  • 2
1 Solution
 
yehudahaCommented:
the script doesn't have 45 lines, this all the script ?
0
 
jahoganAuthor Commented:
Sorry, my fault - cut out the company specific pre-amble.  The line in question is as below:

If Trim(UCase(strLine2))= strLine1 Then

Thanks.

0
 
yehudahaCommented:
i'm gussing strline1 is an array so you need to loop the array with for...next statment

replace this:

  Do Until objFile1.AtEndOfStream
            strLine2 = objFile1.Readline
                If Trim(UCase(strLine2))= strLine1 Then
                              strMatch = True
                End If
            Loop

with this:
 Do Until objFile1.AtEndOfStream
            strLine2 = objFile1.Readline
                For Each line In strLine1
                If Trim(UCase(strLine2))= line Then
                              strMatch = True
                End If
                Next
            Loop

Open in new window

0
 
yehudahaCommented:
in for future scripting try to avoid variables like : x, y, z0

hard to understand and to debugging
0
 
jahoganAuthor Commented:
The element that I asked for assistance on was complete and correct, thank you.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now