From: Russell on
Thank you all.

Russell



"ekkehard.horner" <ekkehard.horner(a)arcor.de> wrote in message
news:4c08dc68$0$6980$9b4e6d93(a)newsspool4.arcor-online.net...
> Russell schrieb:
>> Hello,
>>
>> I have a text file called OS.txt that looks like this:
>>
>> Windows 2000 Professional 5.0 (2195)
> [...]
>> Windows XP Professional 5.1 (2600)
>>
>> I'm trying to write a script that will read the text file then display
>> how many of each Operating System is listed like so:
>>
>> Windows 2000 Professional 1
>> Windows 2000 Server 1
>> Windows 7 Professional 4
>> Windows 7 Ultimate 1
>> Windows NT 4.0 2
>> Windows Server 2003 3
>> Windows Serverr 2008 2
>> Windows XP Professional 3
>
> [...]
>
> Use a dictionary to group/count the OS:
>
> Const cnParts = 2
> Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
> Dim sFSpec : sFSpec = "..\testdata\os.txt"
> Dim dicOS : Set dicOS = CreateObject( "Scripting.Dictionary" )
> Dim tsOS : Set tsOS = oFS.OpenTextFile( sFSpec )
> Dim sKey
> Do Until tsOS.AtEndOfStream
> Dim sLine : sLine = tsOS.ReadLine
> Dim aParts : aParts = Split( sLine, " " )
> If cnParts <= UBound( aParts ) Then
> ReDim Preserve aParts( cnParts )
> dicOS( Join( aParts ) ) = dicOS( Join( aParts ) ) + 1
> Else
> WScript.Echo "can't split", sLine
> End If
> Loop
> tsOs.Close
> For Each sKey In dicOS.Keys
> WScript.Echo sKey, dicOS( sKey )
> Next
>
> output:
>
> Windows 2000 Professional 1
> Windows 2000 Server 1
> Windows 7 Professional 4
> Windows 7 Ultimate 1
> Windows NT 4.0 2
> Windows Server 2003 3
> Windows Serverr 2008 2
> Windows XP Professional 3
>
> The strategy depends on the first three words being relevant for the
> classification.
>
>