Jump to content
Sign in to follow this  
TecGuy

Log file compaire and write specific lines to INI

Recommended Posts

TecGuy

Thanks for looking at this problem. This is my first attempt to use StringRegExp

I am trying to check two log files for specific lines and compare those lines to see if they match.

File 1
Number of files: 791
Number of files transferred: 2
Total file size: 1.19G bytes
Total transferred file size: 126.98K bytes
Literal data: 7.00K bytes
Matched data: 119.98K bytes
File list size: 16.09K
File list generation time: 0.002 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 19.60K
Total bytes received: 3.52K

sent 19.60K bytes  received 3.52K bytes  9.25K bytes/sec
total size is 1.19G  speedup is 51573.24
Terminating secure channel ...

File 2
2010/03/11 00:02:29 [4376] Number of files: 791
2010/03/11 00:02:29 [4376] Number of files transferred: 2
2010/03/11 00:02:29 [4376] Total file size: 1.19G bytes
2010/03/11 00:02:29 [4376] Total transferred file size: 126.98K bytes
2010/03/11 00:02:29 [4376] Literal data: 7.00K bytes
2010/03/11 00:02:29 [4376] Matched data: 119.98K bytes
2010/03/11 00:02:29 [4376] File list size: 16.09K
2010/03/11 00:02:29 [4376] File list generation time: 0.002 seconds
2010/03/11 00:02:29 [4376] File list transfer time: 0.000 seconds
2010/03/11 00:02:29 [4376] Total bytes sent: 19.60K
2010/03/11 00:02:29 [4376] Total bytes received: 3.52K
2010/03/11 00:02:29 [4376] sent 19.60K bytes  received 3.52K bytes  9.25K bytes/sec
2010/03/11 00:02:29 [4376] total size is 1.19G  speedup is 51573.24

If they match then write those lines into an INI file using the following format:

Number of files= 791
Number of files transferred= 2
Total file size= 1.19G bytes
Total transferred file size= 126.98K bytes
Literal data= 7.00K bytes
Matched data= 119.98K bytes
File list size= 16.09K
File list generation time= 0.002 seconds
File list transfer time= 0.000 seconds
Total bytes sent= 19.60K
Total bytes received= 3.52K
sent= 19.60K bytes  received 3.52K bytes  9.25K bytes/sec
total size is= 1.19G  speedup is 51573.24

This is what i have so far.

#include <Array.au3>
Global $searchString = 'c:\Data_status.csv'
$filecontent = FileRead(FileOpen($searchString, 1))

$Key = StringRegExp($filecontent, 'Number',3)
_ArrayDisplay($Key)

I know it is not much. Any help would be much appreciated.

Share this post


Link to post
Share on other sites
GEOSoft

$sFile = FileRead("file1.log")
$aArray_1 = StringRegExp($sFile, "(?i)(?m:^)([a-z].+:.+\d.+)(?:\v|\z)", 3)
$sFile = FileRead("file2.log")
$aArray_2 = StringRegExp($sFile, "(?i)(?m:^).+\]\s([a-z].+:.+\d.+)(?:\v|\z)", 3)
If IsArray($aArray_1) AND IsArray($aArray_2) Then
    ;; You might want to do some checking to make sure the arrays are the same size here
    $iUbound = Ubound($aArray_1)-1
    For $i = 0 To $iUbound
        If $aArray_1[$i] = $aArray_2[$i] Then
             ;; Do Something Here
        EndIf
    Next
Else
    ;; Put some error handling here
EndIf

EDIT: Work with this for now but I'll be back in a few minutes with a better one

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
GEOSoft

As promised. This one will work better since it doesn't require that you check the bounds of 2 arrays so it should avoid the possibility of an array dimension error.

$sFile = FileRead("file1.log")
$aArray = StringRegExp($sFile, "(?i)(?m:^)([a-z].+:.+\d.+)(?:\v|\z)", 3)
$sFile = FileRead("file2.log")
If IsArray($aArray) Then
    $iUbound = Ubound($aArray)-1
    For $i = 0 To $iUbound
        If StringRegExp($sFile, "(?i)(?m:^).+\]\s" & $aArray[$i]) Then
             ;; Do Something Here
        EndIf
    Next
Else
    ;; Put some error handling here
EndIf

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Xenobiologist

Although I like Regex very much, but ...

#include <file.au3>
Dim $lines_A
_FileReadToArray("Logfile1.txt", $lines_A)
$sFile = FileRead("Logfile2.txt")

For $i = 1 To UBound($lines_A) - 1
    If StringInStr($sFile, $lines_A[$i], Default) Then
        ConsoleWrite('+> FOUND : ' & $lines_A[$i] & @CRLF)
    Else
        ConsoleWrite('! NOT FOUND : ' & $lines_A[$i] & @CRLF)
    EndIf
Next

+> FOUND : Number of files: 791
+> FOUND : Number of files transferred: 2
+> FOUND : Total file size: 1.19G bytes
+> FOUND : Total transferred file size: 126.98K bytes
+> FOUND : Literal data: 7.00K bytes
+> FOUND : Matched data: 119.98K bytes
+> FOUND : File list size: 16.09K
+> FOUND : File list generation time: 0.002 seconds
+> FOUND : File list transfer time: 0.000 seconds
+> FOUND : Total bytes sent: 19.60K
+> FOUND : Total bytes received: 3.52K
! NOT FOUND : 
+> FOUND : sent 19.60K bytes received 3.52K bytes 9.25K bytes/sec
+> FOUND : total size is 1.19G speedup is 51573.24
! NOT FOUND : Terminating secure channel ...
+>18:16:59 AutoIT3.exe ended.rc:0

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
TecGuy

Awesome! That is exactly what I needed. Geosoft Thanks for your help.

Xenobiologist Thanks. I did not see yout post until I replied but your solution has solved my next question.

Edited by TecGuy

Share this post


Link to post
Share on other sites
GEOSoft

Although I like Regex very much, but ...

#include <file.au3>
Dim $lines_A
_FileReadToArray("Logfile1.txt", $lines_A)
$sFile = FileRead("Logfile2.txt")

For $i = 1 To UBound($lines_A) - 1
    If StringInStr($sFile, $lines_A[$i], Default) Then
        ConsoleWrite('+> FOUND : ' & $lines_A[$i] & @CRLF)
    Else
        ConsoleWrite('! NOT FOUND : ' & $lines_A[$i] & @CRLF)
    EndIf
Next

+> FOUND : Number of files: 791
+> FOUND : Number of files transferred: 2
+> FOUND : Total file size: 1.19G bytes
+> FOUND : Total transferred file size: 126.98K bytes
+> FOUND : Literal data: 7.00K bytes
+> FOUND : Matched data: 119.98K bytes
+> FOUND : File list size: 16.09K
+> FOUND : File list generation time: 0.002 seconds
+> FOUND : File list transfer time: 0.000 seconds
+> FOUND : Total bytes sent: 19.60K
+> FOUND : Total bytes received: 3.52K
! NOT FOUND : 
+> FOUND : sent 19.60K bytes received 3.52K bytes 9.25K bytes/sec
+> FOUND : total size is 1.19G speedup is 51573.24
! NOT FOUND : Terminating secure channel ...
+>18:16:59 AutoIT3.exe ended.rc:0

That's fine but it would work even better if you dumped that piece of crap _FileReadToArray(). Replace it with _StringToArray()

Func _StringToArray($s_Str)
    If FileExists($s_Str) Then $s_Str = FileRead($s_Str)
    Local $aRtn = StringRegExp($s_Str, "(?i)(?m:^)(.+)(?:\v|\z)", 3)
    If Not @Error Then Return $aRtn
    Return SetError(1)
EndFunc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Xenobiologist

Okay, that will probably work, too. Although it is not 100% the same _FileReadToArray returns.

I just wanted to post a small but fast solution. There might be (of course ) some space left for optimization. :mellow:


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
GEOSoft

Okay, that will probably work, too. Although it is not 100% the same _FileReadToArray returns.

I just wanted to post a small but fast solution. There might be (of course ) some space left for optimization. :mellow:

I think the only difference between them as far as results is possibly StringStripWS($s_Str, 3) to get rid if any empty lines before or after the actual text but I'm not going to bother to confirm that. Besides the 0 based vs 1 based arrays that is. I stopped using _fileReadToArray() months ago and the function I gave was from memory. I can always look it up if I have to but if I gave you the actual code I use then I'd have to kill you and all that other nasty stuff.

EDIT: Oh darn, I forgot to mention that my function will also work with any string input and not just a file so you can even use it with a StdOut stream. Also I'm not too sure how is is on huge strings.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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.