Re: regExp

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Al Dunbar [MS-MVP] (alan-no-drub-spam_at_hotmail.com)
Date: 01/12/05


Date: Tue, 11 Jan 2005 20:45:53 -0700


"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...
> > 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().

Actually, you can get around that. There was a discussion some time ago on
the issue of performance when reading a large file with .ReadAll. The issue
is that, internally, the .readall fills a buffer, then does the equivalent
of: result = result & buffer. Although conventient to use, string
contatenation in variants gets inefficient when the string being
concatenated gets large.

The workaround is to determine the size of the file and .read that many
bytes. This bypasses the buffering/concatenating process, as the script
engine knows up front what size chunk of memory to allocate to the variant,
and reads directly there with no intermediate buffering/concatenating.

/Al

> 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
>
>
>



Relevant Pages

  • Re: password change
    ... Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strComputer ... ' Open the log file for write access. ... is not reset to a separate text file of "missed" computers. ...
    (microsoft.public.windows.server.general)
  • Re: Displaying text output in one external window
    ... application I use to control a script ... the log file and displays it in a ... > Dim oShell ... > Sub SaveScript() ...
    (microsoft.public.scripting.wsh)
  • Re: Reading file from certain point
    ... I need a script to search a log file ... Dim strCTF ... Set objOTF = objFSO.OpenTextFile ...
    (microsoft.public.scripting.vbscript)
  • Re: Loading mulitple files
    ... "Roland Hall" wrote in message ... I now notify the admin with a result status and where the log file was ... > sub prt ... > dim logXML, logtext, arrLogs, arrText ...
    (microsoft.public.scripting.vbscript)
  • Re: struct & array user define type
    ... to get the individual file content from a Filecontents buffer? ... How to assign binary memory data to the previous define struct and get ... > Private Type SizeAPI ... > Dim StructLen As Long ...
    (microsoft.public.vb.winapi)