Dee wrote:
>
> I'm looking for a way of grabing a string from a log file and creating a
> variable from it.
>
> I have looked at the pattern match and Instr functions but non the wiser
> on
> how I can grab a string from a log such as below:
>
> I want to grab the name of the server between the "" in the log file
>
> If anyone has some pointers to the code that I can use that would be
> great
>
> Log File example:
>
> 20080626093137.000000+060,1024, (MS473) Node "myserver.mycomany.com" may
> be
> down. Failed to contact it
>
A VBScript solution:
========
Option Explicit
Dim strLogFile, objFSO, objLog, strLine
Dim intIndex1, intIndex2, strServer
Const ForReading = 1
strLogFile = "c:\Scripts\Example.log"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLog = objFSO.OpenTextFile(strLogFile, ForReading)
Do Until objLog.AtEndOfStream
strLine = objLog.ReadLine
intIndex1 = InStr(strLine, """")
intIndex2 = InStr(intIndex1 + 1, strLine, """")
If (intIndex1 > 0) And (intIndex2 > intIndex1) Then
strServer = Mid(strLine, intIndex1 + 1, intIndex2 - intIndex1 - 1)
Wscript.Echo strServer
End If
Loop
objLog.Close
--
Richard Mueller
MVP Directory Services
Hilltop Lab -
http://www.rlmueller.net
--