Parsing newbie here - I've perused this newsgroup and also msdn and have
been unable to piece together a solution.

I have a logfile of Servers that looks like this:

System information for \\DS02K2:
Uptime: 67 days 6 hours 39 minutes 23 seconds
Kernel version: Microsoft Windows NT, Uniprocessor Free
Product type: Workstation
Product version: 4.0
Service pack: 6
Kernel build number: 1381
Registered organization: Org
Registered owner: Owner
Install date: 12/1/2000, 1:07:12 PM
Activation status: Not applicable
IE version: 5.0100
System root: C:\WINNT
Processors: 1
Processor speed: 600 MHz
Processor type: Intel Pentium III
Physical memory: 128 MB
Video driver: ATI Technologies Inc. 3D RAGE IIC
System information for \\DS01K2:
Uptime: 6 days 8 hours 16 minutes 44 seconds
Kernel version: Microsoft Windows NT, Uniprocessor Free
Product type: Server
Product version: 4.0
Service pack: 6
Kernel build number: 1381
Registered organization: Org
Registered owner: Owner
Install date: 5/25/2001, 1:18:09 PM
Activation status: Not applicable
IE version: 6.0000
System root: C:\WINNT
Processors: 1
Processor speed: 865 MHz
Processor type: Intel Pentium III
Physical memory: 382 MB
Video driver: Matrox Graphics Marvel G200

I need to parse this logfile and return Servername and Processor Speed ONLY.

I've tried SkipLine in a For Next loop to take me down to the Processor
Speed line but haven't been able to get that to function properly.

So far I have something like this:

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\log\srvinfolog.txt", _
ForReading)
Do
strLinetoParse = objTextFile.ReadLine
dtmServerName = Mid(strLinetoParse, 26, 15)
Wscript.Echo "Server: " & dtmServerName
dtmProcessorSpeed = Mid(strLinetoParse, 28, 10)
wscript.Echo "Speed: " & dtmProcessorSpeed

Loop until objTextFile.atEndofStream
objTextFile.Close

Thanks for any help you can provide - this will be a valuable learning
exercise and answered question that won't be repeated.

Re: Text Parsing Help by McKirahan

McKirahan
Wed May 26 14:16:43 CDT 2004

"Ken Osborn" <kenosborn@comcast.net> wrote in message
news:lsydnUjPSYWIeCndRVn-vg@comcast.com...
> Parsing newbie here - I've perused this newsgroup and also msdn and have
> been unable to piece together a solution.
>
> I have a logfile of Servers that looks like this:
>
> System information for \\DS02K2:
> Uptime: 67 days 6 hours 39 minutes 23 seconds
> Kernel version: Microsoft Windows NT, Uniprocessor Free
> Product type: Workstation
> Product version: 4.0
> Service pack: 6
> Kernel build number: 1381
> Registered organization: Org
> Registered owner: Owner
> Install date: 12/1/2000, 1:07:12 PM
> Activation status: Not applicable
> IE version: 5.0100
> System root: C:\WINNT
> Processors: 1
> Processor speed: 600 MHz
> Processor type: Intel Pentium III
> Physical memory: 128 MB
> Video driver: ATI Technologies Inc. 3D RAGE IIC
> System information for \\DS01K2:
> Uptime: 6 days 8 hours 16 minutes 44 seconds
> Kernel version: Microsoft Windows NT, Uniprocessor Free
> Product type: Server
> Product version: 4.0
> Service pack: 6
> Kernel build number: 1381
> Registered organization: Org
> Registered owner: Owner
> Install date: 5/25/2001, 1:18:09 PM
> Activation status: Not applicable
> IE version: 6.0000
> System root: C:\WINNT
> Processors: 1
> Processor speed: 865 MHz
> Processor type: Intel Pentium III
> Physical memory: 382 MB
> Video driver: Matrox Graphics Marvel G200
>
> I need to parse this logfile and return Servername and Processor Speed
ONLY.
>
> I've tried SkipLine in a For Next loop to take me down to the Processor
> Speed line but haven't been able to get that to function properly.
>
> So far I have something like this:
>
> Const ForReading = 1
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile("c:\log\srvinfolog.txt", _
> ForReading)
> Do
> strLinetoParse = objTextFile.ReadLine
> dtmServerName = Mid(strLinetoParse, 26, 15)
> Wscript.Echo "Server: " & dtmServerName
> dtmProcessorSpeed = Mid(strLinetoParse, 28, 10)
> wscript.Echo "Speed: " & dtmProcessorSpeed
>
> Loop until objTextFile.atEndofStream
> objTextFile.Close
>
> Thanks for any help you can provide - this will be a valuable learning
> exercise and answered question that won't be repeated.


Here's a solution;; watch for word-wrap:

Option Explicit
'* Declare Constants
Const cIF1 = "System information for \\"
Const cIF2 = "Processor speed:"
'Const cOTF = "c:\log\srvinfolog.txt"
Const ForReading = 1
'* Declare Variables
Dim strMSG
strMSG = cOTF & vbCrLf
Dim strIF1
Dim strIF2
Dim strOTF
'* Declare Objects
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOTF
Set objOTF = objFSO.OpenTextFile(cOTF,ForReading)
'* Read Log
Do While Not objOTF.atEndofStream
strOTF = objOTF.ReadLine
If InStr(strOTF,cIF1) Then
strIF1 = Trim(Mid(strOTF,Len(cIF1)+1))
strMSG = strMSG & vbCrLf & "Server: " & strIF1
ElseIf InStr(strOTF,cIF2) Then
strIF2 = Trim(Mid(strOTF,Len(cIF2)+1))
strMSG = strMSG & vbTab & "Speed: " & strIF2
End If
Loop
'* Destroy Objects
Set objOTF = Nothing
Set objFSO = Nothing
'* Dislpay Message
WScript.Echo strMSG



Re: Text Parsing Help by Ken

Ken
Wed May 26 15:39:53 CDT 2004

"McKirahan" <News@McKirahan.com> wrote in message
news:v26tc.116606$536.21841835@attbi_s03...
> "Ken Osborn" <kenosborn@comcast.net> wrote in message
> news:lsydnUjPSYWIeCndRVn-vg@comcast.com...
> > Parsing newbie here - I've perused this newsgroup and also msdn and have
> > been unable to piece together a solution.
> >
> > I have a logfile of Servers that looks like this:
> >
>> <snip>
>
> Here's a solution;; watch for word-wrap:
>
> Option Explicit
> '* Declare Constants
> Const cIF1 = "System information for \\"
> Const cIF2 = "Processor speed:"
> 'Const cOTF = "c:\log\srvinfolog.txt"
> Const ForReading = 1
> '* Declare Variables
> Dim strMSG
> strMSG = cOTF & vbCrLf
> Dim strIF1
> Dim strIF2
> Dim strOTF
> '* Declare Objects
> Dim objFSO
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Dim objOTF
> Set objOTF = objFSO.OpenTextFile(cOTF,ForReading)
> '* Read Log
> Do While Not objOTF.atEndofStream
> strOTF = objOTF.ReadLine
> If InStr(strOTF,cIF1) Then
> strIF1 = Trim(Mid(strOTF,Len(cIF1)+1))
> strMSG = strMSG & vbCrLf & "Server: " & strIF1
> ElseIf InStr(strOTF,cIF2) Then
> strIF2 = Trim(Mid(strOTF,Len(cIF2)+1))
> strMSG = strMSG & vbTab & "Speed: " & strIF2
> End If
> Loop
> '* Destroy Objects
> Set objOTF = Nothing
> Set objFSO = Nothing
> '* Dislpay Message
> WScript.Echo strMSG
>

This is AMAZING - thank you!

One question regarding this section of code:

strIF1 = Trim(Mid(strOTF,Len(cIF1)+1))

Trim = removes leading and trailing whitespace
Mid = returns the specified number of characters from the string
strOTF = first argument passed into Mid: the line of the file we are
traversing with ReadLine
Len(cIF1) = second argument passed into Mid: the length of the constant
defined as "System information for \\"

What does the '+1' do? Normally the 3rd argument would indicate the number
of characters to return - does '+1' act as a token of some sort and take
everything after the value of Len(cIF1)?

Thanks again.



Re: Text Parsing Help by McKirahan

McKirahan
Wed May 26 22:19:51 CDT 2004

"Ken Osborn" <kenosborn@comcast.net> wrote in message
news:57KdncLQ7LgEnSjdRVn-hg@comcast.com...
> "McKirahan" <News@McKirahan.com> wrote in message
> news:v26tc.116606$536.21841835@attbi_s03...
> > "Ken Osborn" <kenosborn@comcast.net> wrote in message
> > news:lsydnUjPSYWIeCndRVn-vg@comcast.com...
> > > Parsing newbie here - I've perused this newsgroup and also msdn and
have
> > > been unable to piece together a solution.
> > >
> > > I have a logfile of Servers that looks like this:
> > >
> >> <snip>
> >
> > Here's a solution;; watch for word-wrap:
> >
> > Option Explicit
> > '* Declare Constants
> > Const cIF1 = "System information for \\"
> > Const cIF2 = "Processor speed:"
> > 'Const cOTF = "c:\log\srvinfolog.txt"
> > Const ForReading = 1
> > '* Declare Variables
> > Dim strMSG
> > strMSG = cOTF & vbCrLf
> > Dim strIF1
> > Dim strIF2
> > Dim strOTF
> > '* Declare Objects
> > Dim objFSO
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > Dim objOTF
> > Set objOTF = objFSO.OpenTextFile(cOTF,ForReading)
> > '* Read Log
> > Do While Not objOTF.atEndofStream
> > strOTF = objOTF.ReadLine
> > If InStr(strOTF,cIF1) Then
> > strIF1 = Trim(Mid(strOTF,Len(cIF1)+1))
> > strMSG = strMSG & vbCrLf & "Server: " & strIF1
> > ElseIf InStr(strOTF,cIF2) Then
> > strIF2 = Trim(Mid(strOTF,Len(cIF2)+1))
> > strMSG = strMSG & vbTab & "Speed: " & strIF2
> > End If
> > Loop
> > '* Destroy Objects
> > Set objOTF = Nothing
> > Set objFSO = Nothing
> > '* Dislpay Message
> > WScript.Echo strMSG
> >
>
> This is AMAZING - thank you!
>
> One question regarding this section of code:
>
> strIF1 = Trim(Mid(strOTF,Len(cIF1)+1))
>
> Trim = removes leading and trailing whitespace
> Mid = returns the specified number of characters from the string
> strOTF = first argument passed into Mid: the line of the file we are
> traversing with ReadLine
> Len(cIF1) = second argument passed into Mid: the length of the constant
> defined as "System information for \\"
>
> What does the '+1' do? Normally the 3rd argument would indicate the
number
> of characters to return - does '+1' act as a token of some sort and take
> everything after the value of Len(cIF1)?
>
> Thanks again.

You're welcome.

The syntax for "Mid" is: Mid(string, start[, length])
"length" is optional and "If omitted ... all characters from the start
position to the end of the string are returned.".

The "+1" instructs it to start at the first position after the length of
search string; specifically, if the length of "System information for \\" is
25, we want to start at position 26.



Re: Text Parsing Help by Clas

Clas
Thu May 27 05:06:17 CDT 2004

"Ken Osborn" <kenosborn@comcast.net> wrote in news:57KdncLQ7LgEnSjdRVn-
hg@comcast.com:

> strIF1 = Trim(Mid(strOTF,Len(cIF1)+1))
> What does the '+1' do? Normally the 3rd argument would indicate the number
> of characters to return - does '+1' act as a token of some sort and take
> everything after the value of Len(cIF1)?

Hi,

the +1 is part of the second parameter.
Mid starts to reads one character after cIF1, so at len(cIF1) + 1
to get the Servername.

Regards
Clas

--
So isses und so bleibt's, in engen Hosen reibt's.

RE: Text Parsing Help by anonymous

anonymous
Thu May 27 10:51:05 CDT 2004

Another solution worth looking at is to use ADO to read your log file instead of the FileSystemObject. It will work provided your log file is tab-delimited. There's a good article on MSDN explaining how to do it

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclinic/html/scripting01132004.asp

RE: Text Parsing Help by anonymous

anonymous
Fri May 28 09:46:01 CDT 2004

Each line starts with :: (in case of line wrap.

:: Const ForReading =
:: Set objFSO = CreateObject("Scripting.FileSystemObject"
:: Set objTextFile = objFSO.OpenTextFile("c:\log\srvinfolog.txt", ForReading
:: D
:: strLinetoParse = objTextFile.ReadLin
::
:: if (RegExpTest("System information", strLinetoParse)) The
:: dtmServerName = Mid(strLinetoParse, 26, 15
:: Wscript.Echo "Server: " & dtmServerNam
:: end i
::
:: if (RegExpTest("Processor speed", strLinetoParse)) The
:: dtmProcessorSpeed = Mid(strLinetoParse, 28, 10
:: wscript.Echo "Speed: " & dtmProcessorSpee
:: end i
::
:: Loop until objTextFile.atEndofStrea
:: objTextFile.Clos
::
::
:: Function RegExpTest(patrn, strng
:: Dim regEx, retVal ' Create variable
:: Set regEx = New RegExp ' Create regular expression
:: regEx.Pattern = patrn ' Set pattern
:: regEx.IgnoreCase = True ' Set case sensitivity
:: RegExpTest = regEx.Test(strng) ' Execute the search test
:: End Functio


Re: Text Parsing Help by David

David
Fri May 28 23:10:12 CDT 2004

Ken Osborn wrote:

> Parsing newbie here - I've perused this newsgroup and also msdn and have
> been unable to piece together a solution.
>
> I have a logfile of Servers that looks like this:
>
> System information for \\DS02K2:
> Uptime: 67 days 6 hours 39 minutes 23 seconds
> Kernel version: Microsoft Windows NT, Uniprocessor Free
> Product type: Workstation
> Product version: 4.0
> Service pack: 6
> Kernel build number: 1381
> Registered organization: Org
> Registered owner: Owner
> Install date: 12/1/2000, 1:07:12 PM
> Activation status: Not applicable
> IE version: 5.0100
> System root: C:\WINNT
> Processors: 1
> Processor speed: 600 MHz
> Processor type: Intel Pentium III
> Physical memory: 128 MB
> Video driver: ATI Technologies Inc. 3D RAGE IIC
> System information for \\DS01K2:
> Uptime: 6 days 8 hours 16 minutes 44 seconds
> Kernel version: Microsoft Windows NT, Uniprocessor Free
> Product type: Server
> Product version: 4.0
> Service pack: 6
> Kernel build number: 1381
> Registered organization: Org
> Registered owner: Owner
> Install date: 5/25/2001, 1:18:09 PM
> Activation status: Not applicable
> IE version: 6.0000
> System root: C:\WINNT
> Processors: 1
> Processor speed: 865 MHz
> Processor type: Intel Pentium III
> Physical memory: 382 MB
> Video driver: Matrox Graphics Marvel G200
>
> I need to parse this logfile and return Servername and Processor Speed ONLY.
>
> I've tried SkipLine in a For Next loop to take me down to the Processor
> Speed line but haven't been able to get that to function properly.
>
> So far I have something like this:
>
> Const ForReading = 1
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile("c:\log\srvinfolog.txt", _
> ForReading)
> Do
> strLinetoParse = objTextFile.ReadLine
> dtmServerName = Mid(strLinetoParse, 26, 15)
> Wscript.Echo "Server: " & dtmServerName
> dtmProcessorSpeed = Mid(strLinetoParse, 28, 10)
> wscript.Echo "Speed: " & dtmProcessorSpeed
>
> Loop until objTextFile.atEndofStream
> objTextFile.Close
>
> Thanks for any help you can provide - this will be a valuable learning
> exercise and answered question that won't be repeated.
>
>
I would use the REGEX object
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsobjRegExp.asp

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\temp\test.txt", _
ForReading)
Set regExSystemName = New RegExp
Set regExCPUSpeed = New RegExp
regExSystemName.Pattern = "System information for \\\\(.*):"
regExCPUSpeed.Pattern = "Processor speed:\s+(\d+ MHz)"
Do
strLinetoParse = objTextFile.ReadLine
set Matches = regExSystemName.execute(strlinetoparse)
if(matches.count = 1) then wscript.echo ("found systemname [" &
matches(0).submatches(0) & "]")
set Matches = regExCPUSpeed.execute(strlinetoparse)
if(matches.count = 1) then wscript.echo ("found CPU speed [" &
matches(0).submatches(0) & "]")


Loop until objTextFile.atEndofStream
objTextFile.Close

generates output like
found systemname [DS02K2]
found CPU speed [600 MHz]

and

found systemname [DS01K2]
found CPU speed [865 MHz]