Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need vbscript to compare text files

Posted on 2004-09-14
6
Medium Priority
?
2,816 Views
Last Modified: 2008-05-07
This question is worth  500 Points  
 


I need a vbscript to compare a text file with a list of serial numbers as follows:

Textfile1
12345
23456
23457

and

Textfile2
12345
23456
etc...

If they are equal then exit
if they are Not equal then i will send and e-mail ( i have the e-mail script)

One list will be the constant, and the other will warn of changes.
0
Comment
Question by:chris_v
  • 3
  • 3
6 Comments
 
LVL 13

Expert Comment

by:Michael_D
ID: 12058770
Do you need to know what is the difference?
Do you need compare binary or as text ?
If it is as text, case sensitive or not,
Is trailing extra spaces are ok?
0
 
LVL 2

Author Comment

by:chris_v
ID: 12058822
If they are different I'd like to know what is different.
Compare as text.
not case sensitive
trailing spaces are ok on same line

Thx
0
 
LVL 13

Expert Comment

by:Michael_D
ID: 12058884
What the aprox. size ?
How do you want to see differences? line numbers? or copy of lines?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:chris_v
ID: 12058933
I am tracking hard drive serial numbers from raid servers.  There are only 5 -14 drives on each server.  Serial numbers are gathered using a utility like amcli.exe.  The txt report contains more that just serial numbers.  I will need to filter "Serial Number = XXXXXXXXXXXXX" and compare the numbers to a known list of serial numbers.  If a hard drive is removed or changed the script will report a difference between txt files and send an e-mail to admins.
0
 
LVL 13

Accepted Solution

by:
Michael_D earned 2000 total points
ID: 12059602
Here you go...
=========================

Dim fso, f1,f2, file1, file2
Dim i,j, s, report
Dim found
Dim Diff1 , Diff2, report      
Dim d1,d2

File1="C:\text1.txt"
File2="C:\text2.txt"

set d1 =createObject("Scripting.Dictionary")
set d2 =createObject("Scripting.Dictionary")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.OpenTextFile(file1, 1,0)
Set f2 = fso.OpenTextFile(file2, 1,0)


Do While f1.AtEndOfStream = False
      s = UCase(Trim(f1.ReadLine))

      if s <>"" then
            d1.Add d1.count,s
      end if
loop


Do While f2.AtEndOfStream = False
      s = UCase(Trim(f2.ReadLine))
      if s <>"" then
            d2.Add d2.count,s
      end if
loop

Diff1=""
Diff2=""
found = false
For i = 0 To d1.Count -1
      found = false
      For j = 0 to d2.Count-1
      
            if d1(i)= d2(j) then
                  found=true
                  exit for
            end if
      next
      if not found then
            diff1= diff1 + d1(i) + " "
      end if
next
found = false
For i = 0 To d2.Count -1
      found = false
      For j = 0 to d1.Count-1
      
            if d2(i)= d1(j) then
                  found=true
                  exit for
            end if
      next
      if not found then
            diff2= diff2 + d2(i) + " "
      end if
next

Report=""
if diff1<>"" then
      Report = "Found only in " & file1 & "  " & diff1
end if

if diff2<>"" then
      Report = Report & Chr(13) & chr(10) & "Found only in " & file2 & "  " & diff2
end if



if report="" then
      msgbox "No difference"
else
      msgbox report
end if

===================
I hope it helps.
0
 
LVL 2

Author Comment

by:chris_v
ID: 12059946
Just what I needed...  Thanks.

Note:  report was defined twice....
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question