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