Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

regExp
I have a script that reads a log file line by line.

In the log file I want to pull a date, and string of number similar to a mac
address.

The script starts of by creating the necessary object references
(fileSystemObject, New RegExp, etc)

Then it does 2 input msgboxes.
The first for a date
The second for the string of numbers

These are stored in variables for my regex patterns.

Now I have tried many different variations and usage with patterns but I
can't seem to narrow down the pattern I want.
This is an example of the log file
1/1/2005 12:48:17 AM : Received update - Name: 09900935673,  Device ID:
000001380038b7e3, IP:X.X.X.X
1/1/2005 12:50:14 AM : Received update - Name: 09900935681,  Device ID:
0000013800389f56, IP: X.X.X.X

This log file is very big with many entries. The way string of numbers
(09900935673) and the date are how I can differentiate the log entries.

I want to be able to look at the read the log file match the pattern I want
for the date, and the string of numbers and dump the whole line.

Can anyone please help me?

Thank you,

Juan



Report this thread to moderator Post Follow-up to this message
Old Post
Juan
01-10-05 08:55 PM


Re: regExp
"Juan" <someone@microsoft.com> wrote in message
news:uIVeELz9EHA.2112@TK2MSFTNGP14.phx.gbl...
> I have a script that reads a log file line by line.
>
> In the log file I want to pull a date, and string of number similar to a
mac
> address.
>
> The script starts of by creating the necessary object references
> (fileSystemObject, New RegExp, etc)
>
> Then it does 2 input msgboxes.
> The first for a date
> The second for the string of numbers
>
> These are stored in variables for my regex patterns.
>
> Now I have tried many different variations and usage with patterns but I
> can't seem to narrow down the pattern I want.
> This is an example of the log file
> 1/1/2005 12:48:17 AM : Received update - Name: 09900935673,  Device ID:
> 000001380038b7e3, IP:X.X.X.X
> 1/1/2005 12:50:14 AM : Received update - Name: 09900935681,  Device ID:
> 0000013800389f56, IP: X.X.X.X
>
> This log file is very big with many entries. The way string of numbers
> (09900935673) and the date are how I can differentiate the log entries.
>
> I want to be able to look at the read the log file match the pattern I
want
> for the date, and the string of numbers and dump the whole line.
>
> Can anyone please help me?
>
> Thank you,
>
> Juan
>
>

This process the entire file line by line and doesn't use a regular
expression.

Watch for word-wrap.

Option Explicit
'*
Const cVBS = "Juan.vbs"
Const cLOG = "Juan.log"
'*
Dim arrLOG
Dim intLOG
Dim strLOG
Dim strMDY
strMDY = InputBox("Enter Date (m/d/ccyy)",cVBS,"1/1/2005")
Dim strNUM
strNUM = InputBox("Enter 11-digit number",cVBS,"09900935673")
'*
If strMDY = "" _
Or strNUM = "" _
Or Len(strMDY) < 8 _
Or Len(strNUM) <> 11 Then
WScript.Echo "Invalid input:" & vbCrLf & strMDY & vbCrLf & strNUM
WScript.Quit
End If
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOTF
Set objOTF = objFSO.OpenTextFile(cLOG,1)
strLOG = objOTF.ReadAll()
Set objOTF = Nothing
Set objFSO = Nothing
'*
arrLOG = Split(strLOG,vbCrLf)
For intLOG = 0 To UBound(arrLOG)
strLOG = arrLOG(intLOG)
If  InStr(strLOG,strMDY) > 0 _
And InStr(strLOG,strNUM) > 0 Then
WScript.Echo strLOG
End If
Next




Report this thread to moderator Post Follow-up to this message
Old Post
McKirahan
01-10-05 08:55 PM


Re: regExp
Fantastic,

This works great.

Thank you so MUCH.

Kind regards,

Juan
"McKirahan" <News@McKirahan.com> wrote in message
news:H9OdndDvsvDdKH_cRVn-3w@comcast.com...
> "Juan" <someone@microsoft.com> wrote in message
> news:uIVeELz9EHA.2112@TK2MSFTNGP14.phx.gbl... 
> mac 
> want 
>
> This process the entire file line by line and doesn't use a regular
> expression.
>
> Watch for word-wrap.
>
>     Option Explicit
>    '*
>     Const cVBS = "Juan.vbs"
>     Const cLOG = "Juan.log"
>    '*
>     Dim arrLOG
>     Dim intLOG
>     Dim strLOG
>     Dim strMDY
>         strMDY = InputBox("Enter Date (m/d/ccyy)",cVBS,"1/1/2005")
>     Dim strNUM
>         strNUM = InputBox("Enter 11-digit number",cVBS,"09900935673")
>    '*
>     If strMDY = "" _
>     Or strNUM = "" _
>     Or Len(strMDY) < 8 _
>     Or Len(strNUM) <> 11 Then
>         WScript.Echo "Invalid input:" & vbCrLf & strMDY & vbCrLf & strNUM
>         WScript.Quit
>     End If
>    '*
>     Dim objFSO
>     Set objFSO = CreateObject("Scripting.FileSystemObject")
>     Dim objOTF
>     Set objOTF = objFSO.OpenTextFile(cLOG,1)
>         strLOG = objOTF.ReadAll()
>     Set objOTF = Nothing
>     Set objFSO = Nothing
>    '*
>         arrLOG = Split(strLOG,vbCrLf)
>     For intLOG = 0 To UBound(arrLOG)
>         strLOG = arrLOG(intLOG)
>         If  InStr(strLOG,strMDY) > 0 _
>         And InStr(strLOG,strNUM) > 0 Then
>             WScript.Echo strLOG
>         End If
>     Next
>
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Juan
01-10-05 08:55 PM


Re: regExp
Juan wrote:

> Fantastic,
>
> This works great.

I don't like it, and I thought it was supposed to process "line by line"?

--
Gerry Hickman (London UK)

Report this thread to moderator Post Follow-up to this message
Old Post
Gerry Hickman
01-11-05 01:55 AM


Re: regExp
"Gerry Hickman" <gerry666uk@yahoo.co.uk> wrote in message
news:eFKMI029EHA.3592@TK2MSFTNGP09.phx.gbl...
> Juan wrote:
> 
>
> I don't like it, and I thought it was supposed to process "line by line"?
>
> --
> Gerry Hickman (London UK)

What don't you like?  Do you have an alternative?

It uses ReadAll() to store the entire log file into an array then it uses
Split() to build an array containing each line which are examined one at a
time.



Report this thread to moderator Post Follow-up to this message
Old Post
McKirahan
01-11-05 08:55 AM


Re: regExp
Gerry,

Your right about that.  It is suppose to process line by line and not load
the array.  But Mr. McKirhan took the time to write a nice little script
that can take care of the problem just as long as the log files are small.
If they grow big I will have to Monitor the log file and write another
routine to move the log file and start a new one.

Can you think of the RegExp I need to do the same as the script that was
provided.

Thank you all,

Juan


"Gerry Hickman" <gerry666uk@yahoo.co.uk> wrote in message
news:eFKMI029EHA.3592@TK2MSFTNGP09.phx.gbl...
> Juan wrote:
> 
>
> I don't like it, and I thought it was supposed to process "line by line"?
>
> --
> Gerry Hickman (London UK)



Report this thread to moderator Post Follow-up to this message
Old Post
Juan
01-11-05 08:55 PM


Re: regExp
"Juan" <someone@microsoft.com> wrote in message
news:uSNkLe#9EHA.2788@TK2MSFTNGP15.phx.gbl...
> Gerry,
>
> Your right about that.  It is suppose to process line by line and not load
> the array.  But Mr. McKirhan took the time to write a nice little script
> that can take care of the problem just as long as the log files are small.
> If they grow big I will have to Monitor the log file and write another
> routine to move the log file and start a new one.
>
> Can you think of the RegExp I need to do the same as the script that was
> provided.
>
> Thank you all,
>
> Juan

A regular expression would wtill have to examine the entire log file thus
you can't get around the ReadAll().

It might be a little faster to change:
If  InStr(strLOG,strMDY) > 0 _
to
If  Left(strLOG,Len(strMDY)) <> strMDY _

If you know thatonly one record that meets your "string of numbers" criteria
then you could do an InStr() on the entire log file via:
If InStr(strLOG,strNUM) > 0 Then  ...
to see if it exists.  If it does then extract the "line" that contains it
and test the Date within it.

Option Explicit
'*
Const cVBS = "Juan.vbs"
Const cLOG = "Juan.log"
'*
Dim intBEG
Dim intEND
Dim strLIN
Dim strLOG
Dim strMDY
strMDY = InputBox("Enter Date (m/d/ccyy)",cVBS,"1/1/2005")
Dim strNUM
strNUM = InputBox("Enter 11-digit number",cVBS,"09900935673")
Dim intPOS
'*
If strMDY = "" _
Or strNUM = "" _
Or Len(strMDY) < 8 _
Or Len(strNUM) <> 11 Then
WScript.Echo "Invalid input:" & vbCrLf & strMDY & vbCrLf & strNUM
WScript.Quit
End If
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOTF
Set objOTF = objFSO.OpenTextFile(cLOG,1)
strLOG = vbCrLf & objOTF.ReadAll()
Set objOTF = Nothing
Set objFSO = Nothing
'*
If InStr(strLOG,strNUM) > 0 Then
intPOS = InStr(strLOG,strNUM)
intBEG = InStrRev(strLOG,vbCrLf,intPOS)
intEND = InStr(intPOS,strLOG,vbCrLf)
strLIN = Mid(strLOG,intBEG,intEND)
strLIN = Replace(strLIN,vbCrLf,"")
If InStr(strLOG,strMDY) > 0 Then
WScript.Echo strLIN
End If
End If




Report this thread to moderator Post Follow-up to this message
Old Post
McKirahan
01-11-05 08:55 PM


Re: regExp
Juan wrote:
>
Hi Juan if the usage of a script is not mandatory you might
use a 3rd party app like http://www.logparser.com or
if your os is of the nt line a batch could suffice:

@echo off&setlocal
set /P MyDate="Enter a date   :"
set /P MyNum="Enter a number :"
findstr /I "%MyDate%.*Received.update.-.Name:.%MyNum%" <yourfile-log

you also might have a script running findstr.

HTH

--
Gruesse  Greetings Saludos   Saluti    Salutations
Matthias
---------+---------+---------+---------+---------+---------+---------+

Report this thread to moderator Post Follow-up to this message
Old Post
Matthias Tacke
01-11-05 08:55 PM


Re: regExp
Thank you again Mr. McKirahan and Matthias.

I just learned a few new tricks just from one post.  You guys are awesome.
Keep up the good work.

The first script right now is doing the job without any problems.  I will
experiment with log parser and try out the batch script.

Regards,

Juan
"McKirahan" <News@McKirahan.com> wrote in message
news:B7SdndDnrYjzdH7cRVn-tw@comcast.com...
> "Juan" <someone@microsoft.com> wrote in message
> news:uSNkLe#9EHA.2788@TK2MSFTNGP15.phx.gbl... 
load 
small. 
>
> A regular expression would wtill have to examine the entire log file thus
> you can't get around the ReadAll().
>
> It might be a little faster to change:
>     If  InStr(strLOG,strMDY) > 0 _
> to
>     If  Left(strLOG,Len(strMDY)) <> strMDY _
>
> If you know thatonly one record that meets your "string of numbers"
criteria
> then you could do an InStr() on the entire log file via:
>     If InStr(strLOG,strNUM) > 0 Then  ...
> to see if it exists.  If it does then extract the "line" that contains it
> and test the Date within it.
>
>     Option Explicit
>    '*
>     Const cVBS = "Juan.vbs"
>     Const cLOG = "Juan.log"
>    '*
>     Dim intBEG
>     Dim intEND
>     Dim strLIN
>     Dim strLOG
>     Dim strMDY
>         strMDY = InputBox("Enter Date (m/d/ccyy)",cVBS,"1/1/2005")
>     Dim strNUM
>         strNUM = InputBox("Enter 11-digit number",cVBS,"09900935673")
>     Dim intPOS
>    '*
>     If strMDY = "" _
>     Or strNUM = "" _
>     Or Len(strMDY) < 8 _
>     Or Len(strNUM) <> 11 Then
>         WScript.Echo "Invalid input:" & vbCrLf & strMDY & vbCrLf & strNUM
>         WScript.Quit
>     End If
>    '*
>     Dim objFSO
>     Set objFSO = CreateObject("Scripting.FileSystemObject")
>     Dim objOTF
>     Set objOTF = objFSO.OpenTextFile(cLOG,1)
>         strLOG = vbCrLf & objOTF.ReadAll()
>     Set objOTF = Nothing
>     Set objFSO = Nothing
>    '*
>     If InStr(strLOG,strNUM) > 0 Then
>         intPOS = InStr(strLOG,strNUM)
>         intBEG = InStrRev(strLOG,vbCrLf,intPOS)
>         intEND = InStr(intPOS,strLOG,vbCrLf)
>         strLIN = Mid(strLOG,intBEG,intEND)
>         strLIN = Replace(strLIN,vbCrLf,"")
>         If InStr(strLOG,strMDY) > 0 Then
>             WScript.Echo strLIN
>         End If
>     End If
>
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Juan
01-11-05 08:55 PM


Re: regExp
Juan wrote:

> Your right about that.  It is suppose to process line by line and not load
> the array.  But Mr. McKirhan took the time to write a nice little script
> that can take care of the problem

I know. I wasn't going to say anything, but I thought it was worth it
because otherwise we don't learn anything.

See points above.

--
Gerry Hickman (London UK)

Report this thread to moderator Post Follow-up to this message
Old Post
Gerry Hickman
01-12-05 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

WSH archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:21 AM.

 

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.