From: saskia34 on
Can somebody help me with a vbscript.

I want search computers in 2 textfiles, if the computers matched then write
in Computers01.txt a text like "OK"

i want read the first computers01.txt en match they other text file (
computers02.txt )

Example:


computers01.txt computers02.txt
----------------- -----------------
server001,OK server003
server002, server001
server003,OK Server045
SERVER673
server0089


Is it possible to make it not case sensitive, or must i convert the
textfiles convert to Low letters first ?



thanks a lot for help

Saskia


From: Pegasus [MVP] on


"saskia34" <nospam(a)hotmail.nl> wrote in message
news:25968$4c87ec43$5ed3224d$2603(a)cache5.tilbu1.nb.home.nl...
> Can somebody help me with a vbscript.
>
> I want search computers in 2 textfiles, if the computers matched then
> write in Computers01.txt a text like "OK"
>
> i want read the first computers01.txt en match they other text file (
> computers02.txt )
>
> Example:
>
>
> computers01.txt computers02.txt
> ----------------- -----------------
> server001,OK server003
> server002, server001
> server003,OK Server045
> SERVER673
> server0089
>
>
> Is it possible to make it not case sensitive, or must i convert the
> textfiles convert to Low letters first ?
>
>
>
> thanks a lot for help
>
> Saskia

Let's have a look at the script you've got so far.

From: James Whitlow on
"saskia34" <nospam(a)hotmail.nl> wrote in message
news:25968$4c87ec43$5ed3224d$2603(a)cache5.tilbu1.nb.home.nl...
> Can somebody help me with a vbscript.
>
> I want search computers in 2 textfiles, if the computers matched then
> write in Computers01.txt a text like "OK"
>
> i want read the first computers01.txt en match they other text file (
> computers02.txt )
>
> Example:
>
>
> computers01.txt computers02.txt
> ----------------- -----------------
> server001,OK server003
> server002, server001
> server003,OK Server045
> SERVER673
> server0089
>
>
> Is it possible to make it not case sensitive, or must i convert the
> textfiles convert to Low letters first ?

No, you don't need to convert your files. There are many ways to do what
you want. Below is a quick example using the dictionary object.

Option Explicit

Dim oDict, oFSO, oFile1, oFile2
Dim sFile1, sFile2, sComp

Set oDict = CreateObject("Scripting.Dictionary")
Set oFSO = CreateObject("Scripting.FileSystemObject")

oDict.CompareMode = 1 'Case insensitive text compare

sFile1 = "computers01.txt"
sFile2 = "computers02.txt"

Set oFile1 = oFSO.OpenTextFile(sFile1, 1)
Set oFile2 = oFSO.OpenTextFile(sFile2, 1)

'Read all of the computers from 'sFile1' into the dictionary
Do Until oFile1.AtEndOfStream
sComp = Trim(oFile1.ReadLine)
If Not oDict.Exists(sComp) AND Len(sComp) > 0 Then
oDict.Add sComp, Empty
End If
Loop

oFile1.Close

'Loop through 'sFile2' looking for matches in the dictionary
Do Until oFile2.AtEndOfStream
sComp = Trim(oFile2.ReadLine)
If oDict.Exists(sComp) Then oDict(sComp) = ",OK"
Loop

'Loop through the dictionary & write the results back to 'sFile1'
Set oFile1 = oFSO.OpenTextFile(sFile1, 2, True)
For Each sComp in oDict.Keys
oFile1.WriteLine sComp & oDict(sComp)
Next

oFile1.Close

MsgBox "Complete!"

From: saskia34 on
Thanks James the script works fine, but only the first file (
computers01.txt ) they have more collums sorry for that.
The computers stay one the Second colomm.
If have correct this with a Array command but this is not correct.


computers01.txt
------------------
09-09-2010,server003,locked,etc,



Option Explicit

Dim oDict, oFSO, oFile1, oFile2
Dim sFile1, sFile2, sComp

Set oDict = CreateObject("Scripting.Dictionary")
Set oFSO = CreateObject("Scripting.FileSystemObject")

oDict.CompareMode = 1 'Case insensitive text compare

sFile1 = "computers01.txt"
sFile2 = "computers02.txt"

Set oFile1 = oFSO.OpenTextFile(sFile1, 1)
Set oFile2 = oFSO.OpenTextFile(sFile2, 1)

'Read all of the computers from 'sFile1' into the dictionary
Do Until oFile1.AtEndOfStream
sComp = Trim(oFile1.ReadLine)
arrList = Split(sComp , ",")
If Not oDict.Exists(arrList(1)) AND Len(arrList(1)) > 0 Then
oDict.Add arrList(1), Empty
End If
Loop

oFile1.Close

'Loop through 'sFile2' looking for matches in the dictionary
Do Until oFile2.AtEndOfStream
sComp = Trim(oFile2.ReadLine)
If oDict.Exists(sComp) Then oDict(sComp) = ",OK"
Loop

'Loop through the dictionary & write the results back to 'sFile1'
Set oFile1 = oFSO.OpenTextFile(sFile1, 2, True)
For Each sComp in oDict.Keys
oFile1.WriteLine sComp & oDict(sComp)
Next

oFile1.Close

MsgBox "Complete!"





"James Whitlow" <jwhitlow.60372693(a)bloglines.com> schreef in bericht
news:OiGZr38TLHA.5716(a)TK2MSFTNGP02.phx.gbl...
> "saskia34" <nospam(a)hotmail.nl> wrote in message
> news:25968$4c87ec43$5ed3224d$2603(a)cache5.tilbu1.nb.home.nl...
>> Can somebody help me with a vbscript.
>>
>> I want search computers in 2 textfiles, if the computers matched then
>> write in Computers01.txt a text like "OK"
>>
>> i want read the first computers01.txt en match they other text file (
>> computers02.txt )
>>
>> Example:
>>
>>
>> computers01.txt computers02.txt
>> ----------------- -----------------
>> server001,OK server003
>> server002, server001
>> server003,OK Server045
>> SERVER673
>> server0089
>>
>>
>> Is it possible to make it not case sensitive, or must i convert the
>> textfiles convert to Low letters first ?
>
> No, you don't need to convert your files. There are many ways to do what
> you want. Below is a quick example using the dictionary object.
>
> Option Explicit
>
> Dim oDict, oFSO, oFile1, oFile2
> Dim sFile1, sFile2, sComp
>
> Set oDict = CreateObject("Scripting.Dictionary")
> Set oFSO = CreateObject("Scripting.FileSystemObject")
>
> oDict.CompareMode = 1 'Case insensitive text compare
>
> sFile1 = "computers01.txt"
> sFile2 = "computers02.txt"
>
> Set oFile1 = oFSO.OpenTextFile(sFile1, 1)
> Set oFile2 = oFSO.OpenTextFile(sFile2, 1)
>
> 'Read all of the computers from 'sFile1' into the dictionary
> Do Until oFile1.AtEndOfStream
> sComp = Trim(oFile1.ReadLine)
> If Not oDict.Exists(sComp) AND Len(sComp) > 0 Then
> oDict.Add sComp, Empty
> End If
> Loop
>
> oFile1.Close
>
> 'Loop through 'sFile2' looking for matches in the dictionary
> Do Until oFile2.AtEndOfStream
> sComp = Trim(oFile2.ReadLine)
> If oDict.Exists(sComp) Then oDict(sComp) = ",OK"
> Loop
>
> 'Loop through the dictionary & write the results back to 'sFile1'
> Set oFile1 = oFSO.OpenTextFile(sFile1, 2, True)
> For Each sComp in oDict.Keys
> oFile1.WriteLine sComp & oDict(sComp)
> Next
>
> oFile1.Close
>
> MsgBox "Complete!"