PDA

View Full Version : Read a log file and abstract data into a seperate file (W2K)



ScottSouthgate
05-17-2004, 08:57 AM
I am trying to write a vb script to open a log file then line-by-line read the contents checking each line for a specific phrase. If the phrase is found then output that line to a new log file.

I have tried using the 'ReadAll' object, but I think 'Readline' will be more appropriate as I can then run a subroutine to check each line for the specific phrase.

I am quite a newbie to vb and would appreciate some help on checking a line for a specific phrase.

I know how to open a text file and readline into a variable. What I dont know is how to check the variable to see if it contains the phrase.

I am guessing here, but think it will require a Do - While or For - Next loop.

example;

Dim phrase
phrase = "cmd=log off"
set log = fso.OpenTextFile(C:\myfile.log")
line = log.ReadLine (line1 **will require some kind of loop to read all lines until EOF is reached)
**check line to see if phrase exists
If line contains phrase - writeline to another file

Else continue to the next line.


I hope that makes some sort of sense!!

I don't think what I am trying to do is too difficult, I am simply struggling on the syntax on how to check the variable content and also how to read the next line(s) in the file.

Any help would be greatly appreciated.


Many thanks,


Scott S.

dineshcooper
05-17-2004, 05:50 PM
The post

titled: Create a log of..
Poster: Orcie

should have everything you need

Cheers

hwolek
05-21-2004, 07:46 AM
Try something like this:
Dim phrase

phrase = "cmd=log off"
Set fso = CreateObject("Scripting.FileSystemObject")
Set Log = fso.OpenTextFile("C:\myfile.Log")
Do While Not Log.AtEndOfStream
line = Log.ReadLine
If InStr(LCase(line), phrase) <> 0 Then
' Write line to other file
End If
Loop

Heinz