Jump to content
Sign in to follow this  
Pignara

StringRegExp question

Recommended Posts

Pignara

hi

i try to make a script thats read from one point to another and save the text in a txt file

the log looks like:

[service]

Opened log at 19/04/2007 10:49:03.984 ----------> Grabbed

Failed to log an event

[Other]

Dropping event

Failed to deliver

[service]

Opened log at 20/04/2007 11:56:97.957 ----------> Grabbed

Failed to log an event

[service]

Opened log at 27/04/2007 09:54:92.132 ----------> Not Grabbed

Failed to log an event

[Other]

Dropping event

Failed to deliver

whit this code:

Func _Readmylog($mylog, $whattoread)
   $array = StringRegExp(FileRead($mylog), '(?s)(?i)\[' & $whattoread & ']\s*(.*?)\s*(\[|$)', 3)
   If IsArray($array) = 0 Then Return SetError(1, 0, '') 
   $contents = _ArrayToString($array, @LF)
   $contents = StringSplit($contents, @LF)
   $data = $contents[0] 
   $i = 1
    While 1
        If StringLeft(StringStripWS($contents[$i], 8), 1) = '(' Or StringLeft(StringStripWS($contents[$i], 8), 1) = '[' Or StringLeft(StringStripWS($contents[$i], 8), 1) = '' Then
            _ArrayDelete($contents, $i)
            $data = $data - 1
            $i = $i + 1
            If $i > $data Then ExitLoop
        Else
            $i = $i + 1
            If $i > $data Then ExitLoop
        EndIf
    WEnd
    _ArrayDelete($contents, 0)
    $contents = _ArrayToString($contents, @LF)
    Return StringSplit($contents, @LF)
EndFunc

$mylog = ('test.log')
$whattoread = ('Service')
$Array = _Readmylog($mylog, $whattoread)

For $i = 1 To $Array[0]
    FileWriteLine('Result.txt', $Array[$i] & @CRLF)
Next

The problem is with the 3° and 4° [service] block because the 4°block is not saved to my Result.txt :)

any idea???

please help me.

Pignara

Share this post


Link to post
Share on other sites
Pignara

Soooo... no one as any ideas? Sorry for bumping.

Edit....obviously the problem is with the 2° and 3° [service] block . :">

Pignara

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.