Pulling info out of a text log file and manipulating it
- From: Jamie Hopwood <jamie.hopwood@-+nospam=-hotmail.com>
- Date: Wed, 21 Mar 2007 10:58:25 -0400
I have a log file that is the output from a weekly test of our branch
routers back connection
the single text file contains about 150 entries each one looking like
this
-----------------------------------------
Branch Number 999
ÿû
ÿû
ÿýÿý
Username: *******
Password:
WELCOME TO THE TEST ENVIRONMENT ROUTER
******-TEST-BRANCH#ping 1.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
......
Success rate is 0 percent (0/5)
******-TEST-BRANCH#
-----------------------------------------
what i need to do is parse this info for each entry pulling the
Branch number... and success rate is...
i'm not sure how to do this however i need to pull both pieces of info
an output them to another text file so that of the success rate is 0
it will say failed and if it's something other than 0 it will say
passed
so it lookes something like this
------------------------------
Branch Number 999
Failed
------------------------------
------------------------------
Branch Number XXX
Passed
------------------------------
and so on
now i have figured out using regular expressions how to pull Success
rate is XXX and output it to a file
and here is the code i have so far
Dim file, FSO, TextStream, objFile
Set FSO = CreateObject("Scripting.FileSystemObject")
Set file =
FSO.GetFile("V:\SCRIPTS\ISDNCHECKER2\Full_Log-3212007-test.txt") 'file
in which email ids are embedded
Set objFile =
FSO.CreateTextFile("V:\SCRIPTS\ISDNCHECKER2\parsed_Log-3212007.txt",
True) 'file to which the email ids are written
Set TextStream = file.OpenAsTextStream(1,-2)
Do While Not TextStream.AtEndOfStream
Dim Line
Line = TextStream.readline
Parse Line
Loop
'objFile.CloseSet
'objFile = nothing
Set TextStream = nothing
Set FSO = nothing
Sub Parse(vSearch)
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = "Success rate is [0-9]+ percent"
RegEx.IgnoreCase = True
RegEx.Global = True
Set expressionmatch = RegEx.Execute(vSearch)
If expressionmatch.Count > 0 Then
For Each expressionmatched in expressionmatch
'Msgbox(expressionmatched.Value)
objFile.Write "------------------------"
Objfile.writeBlankLines(1)
objFile.Write(expressionmatched.Value)
Objfile.writeBlankLines(1)
objFile.Write "------------------------"
Objfile.writeBlankLines(1)
Next
End If
Set RegEx = Nothing
End Sub
.
- Prev by Date: Re: VBscript embed images in HTML email body
- Next by Date: If a drive is already mapped, then open Windows Explorer
- Previous by thread: VBScript & CDOEXM - trying to mail enable a list of users
- Next by thread: If a drive is already mapped, then open Windows Explorer
- Index(es):