Prev: Count how many specific character there is in a string(readed from txt file)
Next: Rename files to match date stamp
From: Russell on 3 Jun 2010 23:44 Hello, I have a text file called OS.txt that looks like this: Windows 2000 Professional 5.0 (2195) Windows 2000 Server 5.0 (2195) Windows 7 Professional 6.1 (7600) Windows 7 Professional 6.1 (7600) Windows 7 Professional 6.1 (7600) Windows 7 Professional 6.1 (7600) Windows 7 Ultimate 6.1 (7100) Windows NT 4.0 Windows NT 4.0 Windows Server 2003 5.2 (3790) Windows Server 2003 5.2 (3790) Windows Server 2003 5.2 (3790) Windows Serverr 2008 Standard 6.0 (6002) Windows Serverr 2008 Standard 6.0 (6001) Windows XP Professional 5.1 (2600) Windows XP Professional 5.1 (2600) 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 Any ideas on how to do this? Thanks. Russell
From: pooradmin on 4 Jun 2010 00:19 On Jun 3, 11:44 pm, "Russell" <rhrom...(a)verizon.net> wrote: > Hello, > > I have a text file called OS.txt that looks like this: > > Windows 2000 Professional 5.0 (2195) > Windows 2000 Server 5.0 (2195) > Windows 7 Professional 6.1 (7600) > Windows 7 Professional 6.1 (7600) > Windows 7 Professional 6.1 (7600) > Windows 7 Professional 6.1 (7600) > Windows 7 Ultimate 6.1 (7100) > Windows NT 4.0 > Windows NT 4.0 > Windows Server 2003 5.2 (3790) > Windows Server 2003 5.2 (3790) > Windows Server 2003 5.2 (3790) > Windows Serverr 2008 Standard 6.0 (6002) > Windows Serverr 2008 Standard 6.0 (6001) > Windows XP Professional 5.1 (2600) > Windows XP Professional 5.1 (2600) > 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 > > Any ideas on how to do this? > > Thanks. > > Russell Any chance you would want to do this in powershell? get-content file.txt | group-object | select name, count
From: Russell on 4 Jun 2010 00:30 Thanks, but I prefer vbscript. Russell "pooradmin" <jskiba99(a)gmail.com> wrote in message news:ab4d3316-bd2c-4668-8cce-e6e74073c38b(a)a30g2000yqn.googlegroups.com... On Jun 3, 11:44 pm, "Russell" <rhrom...(a)verizon.net> wrote: > Hello, > > I have a text file called OS.txt that looks like this: > > Windows 2000 Professional 5.0 (2195) > Windows 2000 Server 5.0 (2195) > Windows 7 Professional 6.1 (7600) > Windows 7 Professional 6.1 (7600) > Windows 7 Professional 6.1 (7600) > Windows 7 Professional 6.1 (7600) > Windows 7 Ultimate 6.1 (7100) > Windows NT 4.0 > Windows NT 4.0 > Windows Server 2003 5.2 (3790) > Windows Server 2003 5.2 (3790) > Windows Server 2003 5.2 (3790) > Windows Serverr 2008 Standard 6.0 (6002) > Windows Serverr 2008 Standard 6.0 (6001) > Windows XP Professional 5.1 (2600) > Windows XP Professional 5.1 (2600) > 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 > > Any ideas on how to do this? > > Thanks. > > Russell Any chance you would want to do this in powershell? get-content file.txt | group-object | select name, count
From: ekkehard.horner on 4 Jun 2010 07:05 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.
From: "Dave "Crash" Dummy" on 4 Jun 2010 07:47
Russell wrote: > > Thanks, but I prefer vbscript. Set d = CreateObject("Scripting.Dictionary") Set fso=CreateObject("Scripting.FileSystemObject") Set listFile=fso.OpenTextFile("os.txt") do until listFile.AtEndOfStream line=listFile.readLIne line=trim(line) if d.Exists(line) then d.Item(line)=d.Item(line) + 1 else d.Add line, 1 end if loop a=d.keys dim listCount For i = 0 To d.Count -1 ' Iterate the array. listCount=listCount & a(i) & " " & d.Item(a(i)) & vbCRLF Next msgbox listCount -- Crash Life is short. Eat dessert first. |