Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Re: Find the differences in two text files

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2642
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Re: Find the differences in two text files
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 [2]
Login
Message << Older Topic   Newer Topic >>
 Re: Find the differences in two text files - 4/11/2005 7:27:42 AM   
  esnmb

 

Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
Got it. Thanks!

(in reply to esnmb)
 
 
Post #: 21
 
 Re: Find the differences in two text files - 4/11/2005 7:29:55 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
[|)]

(in reply to esnmb)
 
 
Post #: 22
 
 Re: Find the differences in two text files - 4/11/2005 7:31:49 AM   
  esnmb

 

Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
token, one more thing, how are these items and keys being added without the hash.add? I feel like I'm being really thick headed, but I would really like to grasp this.

(in reply to esnmb)
 
 
Post #: 23
 
 Re: Find the differences in two text files - 4/11/2005 8:23:19 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
There are two methods you can use to add a key, just like there are two methods you could use with user.homedirectory. (You could use user.Get("homedirectory") or simply user.homedirectory)

You could do it with either ways, but I tend to stick to only ONE method simply because I can do either assignments or comparisons without the ADD.

(in reply to esnmb)
 
 
Post #: 24
 
 Re: Find the differences in two text files - 4/11/2005 8:28:48 AM   
  esnmb

 

Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
Interesting. Is there somewhere that shows that? Anyway, here is my completed script.

========================================

' ************************************************
' *
' * Create text files from AD search then compare
' * them to create a CSV with the differences.
' *
' ************************************************

On Error Resume Next

MsgBox "Another Message Box will alert you when the script is complete",,"INFORMATIONAL"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("c:\All.txt")
Set objFile1 = objFSO.CreateTextFile("c:\Group.txt")
Set objFile2 = objFSO.CreateTextFile("c:\Diff.csv")
objFile2.WriteLine "Members not in Microsoft IP Printing" & vbCrLf

Set objOU = GetObject _
("LDAP://ou=Users,ou=All Users,dc=mlnusa,dc=com")

ObjOU.Filter = Array("user")

For Each objUser in objOU
objFile.WriteLine objUser.CN
arrMemberOf = objUser.GetEx("memberOf")
For Each Group in arrMemberOf
If InStr(Group, "CN=Microsoft IP Printing") Then
objFile1.WriteLine objUser.CN
End If
Next
Next

objFile.Close
objFile1.Close

' *******************************************
' *
' * Filter out differences in the text files.
' *
' *******************************************

Const TextMode = 1

Set hash = CreateObject("Scripting.Dictionary")
Set hash2 = CreateObject("Scripting.Dictionary")

hash.CompareMode = TextMode
hash1.CompareMode = TextMode

file1 = "c:\All.txt"
file2 = "c:\Group.txt"

Set ts = objFSO.OpenTextFile(file1,1)

Do Until ts.AtEndOfStream
temp = ts.ReadLine
hash.Item(temp) = 1
Loop
ts.Close

Set ts = objFSO.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
ts.Close

For Each key In hash.Keys
If hash(key) = 1 Then
hash2(key) = True
End If
Next

For Each key In hash2.Keys
objFile2.WriteLine Chr(34) & key & Chr(34) & ","
Next

objFile2.Close

objFSO.DeleteFile("c:\All.txt")
objFSO.DeleteFile("c:\Group.txt")

MsgBox "The script has finished executing.",,"COMPLETE"

(in reply to esnmb)
 
 
Post #: 25
 
 Re: Find the differences in two text files - 4/11/2005 8:30:36 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Pardon me, .....shows what ? within the code ?

(in reply to esnmb)
 
 
Post #: 26
 
 Re: Find the differences in two text files - 4/11/2005 8:33:23 AM   
  esnmb

 

Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
Sorry. Is there some documentation that demonstrates the two different methods?

(in reply to esnmb)
 
 
Post #: 27
 
 Re: Find the differences in two text files - 4/11/2005 8:58:14 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
MSDN/Technet =)

I can't remember the exact URL. A search should be sufficient.

For example, the following 2 lines do exactly the same thing.

hash.Add "John","Male"
hash.Item("John") = "Male"

(in reply to esnmb)
 
 
Post #: 28
 
 Re: Find the differences in two text files - 4/11/2005 9:00:47 AM   
  esnmb

 

Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
So John is the Key and Male is the Item. Very cool.

(in reply to esnmb)
 
 
Post #: 29
 
 Re: Find the differences in two text files - 4/11/2005 9:23:44 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
yup. Did that clearify the confusion you had before ? I mean, was that what you don't understand in my code because I used hash.Item(key) = item ?

or you are still confused by something in my code ?

(in reply to esnmb)
 
 
Post #: 30
 
 Re: Find the differences in two text files - 4/11/2005 2:34:43 PM   
  kramer

 

Posts: 6
Score: 0
Joined: 4/11/2005
From:
Status: offline
Sorry for asking such a stupid or a simple question. I am new to scripting. Can someone please answer to my following questions on below code.

Do Until ts.AtEndOfStream
temp = ts.ReadLine
If hash.Exists(temp) Then

' What is + 1 for on below line ?

hash.Item(temp) = hash.Item(temp) + 1
Else

' What does the below line do

hash.Item(temp) = 1
End If
Loop
-----------------------------------------------------------

Thanks in Advance.

(in reply to esnmb)
 
 
Post #: 31
 
 Re: Find the differences in two text files - 4/11/2005 2:56:26 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
1. It increments the value of (originally equals to 1) the key called "temp" (which is a variable that holds a string value gathered from the text file) by 1

2. It assigns a value of 1 to the key called "temp"

(in reply to esnmb)
 
 
Post #: 32
 
 Re: Find the differences in two text files - 4/12/2005 12:45:51 AM   
  esnmb

 

Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
I'm good now token. That was the confusion. Thanks for all your help.

(in reply to esnmb)
 
 
Post #: 33
 
 Re: Find the differences in two text files - 4/12/2005 6:07:12 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
esnmb, anytime =)

(in reply to esnmb)
 
 
Post #: 34
 
 Re: Find the differences in two text files - 4/12/2005 12:19:31 PM   
  kramer

 

Posts: 6
Score: 0
Joined: 4/11/2005
From:
Status: offline
Thanks Token for the explanation.

(in reply to esnmb)
 
 
Post #: 35
 
 Re: Find the differences in two text files - 4/13/2005 6:48:00 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
You're welcome kramer.

(in reply to esnmb)
 
 
Post #: 36
 
 
Page:  <<   < prev  1 [2]
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Re: Find the differences in two text files Page: <<   < prev  1 [2]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts