Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > grab a String (server name) from log

Reply
Thread Tools Display Modes

grab a String (server name) from log

 
 
Dee
Guest
Posts: n/a

 
      06-26-2009

Hi

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


--
Dee
 
Reply With Quote
 
 
 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      06-26-2009

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


 
Reply With Quote
 
Dee
Guest
Posts: n/a

 
      06-26-2009

Thanks Richard, I wil give this a go, I managed in the end to use the pattern
below in my script which now matches between the quotes

objRE.Pattern = """.*"""

Cheers

--
Dee


"Richard Mueller [MVP]" wrote:

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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IE 8.0 user agent string.... (2 IE because of post platform string yoav Internet Explorer 3 03-27-2009 12:52 AM
Grab local session through Remote Desktop on Windows Server 2003? Noozer Windows Server 1 03-26-2008 11:29 AM
String PRODUCT_NAME was not found in string table Extracampine Windows Vista General Discussion 3 02-12-2007 11:15 AM
How do I convert this physical string into logical string? keandi Windows Vista Drivers 6 10-31-2006 07:11 PM
Search a file for string and repolace string?? Paul Scripting 0 07-01-2003 10:32 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59