Sign in to follow this  
Followers 0
skaboy71

Crazy

4 posts in this topic

#1 ·  Posted (edited)

I am going crazy !!!

I am trying to parse some logs that have field delimiters and I want to remove all the duplicate logs for each day that have the same message txt. The logs might look like this:

040228~error~11565~This is some txt to describe some error1

040228~error~11566~This is some txt to describe some error1

040228~error~11567~This is some txt to describe some error1

040228~error~11568~This is some txt to describe some error1

040228~error~11569~This is some txt to describe some error1

040228~error~11570~This is some txt to describe some error5

040228~error~11571~This is some txt to describe some error5

040228~error~11572~This is some txt to describe some error5

040228~error~11573~This is some txt to describe some error5

The first field is the date and as you can see I have some lines that have duplicate data in 2 or more fields. I want to write all the lines for each day that have unique data in the last field.

Here is what I have but it keeps getting stuck in the loop ???

I am very new to any type of programming, other than HTML and thhis is making me CRAZY !!! ....Any help would be greatly appreciated. Perhaps there is an easier way to get the same results ?

$rname = @MON&"-"&@MDAY&"-"&@YEAR&"_rep.txt"

Global $report = FileOpen   ( "C:\dreports\"&$rname, 2 )

Global $log = FileOpen ( "C:\logs\BDC02_app.txt", 0 )
If $log = -1 Then
   MsgBox(0, "Error", "Unable to open file.")
   Exit
EndIf
$first = FileReadLine($log)
FileWriteLine("$first", $report)

While 1
   $line = FileReadLine($log)
   If @error = -1 Then ExitLoop
$done = 0
$linepts = StringSplit($line, "~")
    While 1
    $compline = FileReadLine($report)
    If @error = -1 Then ExitLoop
    $clinepts = StringSplit($compline, "~")
    If $linepts[1] == $clinepts[1] AND $linepts[5] == $clinepts[5] Then
    $done = 1
    EndIf
    WEnd
If $done = 0 Then
FileWriteLine($report,$line)    
EndIf
WEnd

FileClose($log)
FileClose($report)
Edited by skaboy71

I'd rather laugh with the sinners than cry with the saints..... The sinners are much more fun....Only the good die young. -- Billy Joel

Share this post


Link to post
Share on other sites



First I want to say that you are doing very well for being new to programming. Your original code sample is well structured, and I beleive that you're showing great promise. :whistle:

I've noticed some minor nuances with my workings with AutoIt -- I hesitate to use the word "bugs" since I believe that these nuances were intentionally programmed. Anyway, the following code should work for you:

$rname = @MON & "-" & @MDAY & "-" & @YEAR & "_rep.txt"
$summary = "C:\dreports\" & $rname
$source = "C:\logs\BDC02_app.txt"

If FileExists($source) Then
  $log = FileOpen($source, 0)
  If $log == -1 Then
    MsgBox(0, "Error", "Unable to open source log file.")
    Exit(1)
  EndIf

  While 1
    $line = FileReadLine($log)
    If @error == -1 Then ExitLoop
    $linepts = StringSplit($line, "~")

    $done = 0

    If FileExists($summary) Then
      $report = FileOpen($summary, 0)
      If @error <> -1 Then
        While 1
          $compline = FileReadLine($report)
          If @error <> 0 Then ExitLoop

          $clinepts = StringSplit($compline, "~")

          If $clinepts[0] > 1 Then
            If $linepts[1] == $clinepts[1] AND StringStripCR($linepts[4]) == StringStripCR($clinepts[4]) Then
              $done = 1
              ExitLoop
            EndIf
          EndIf
        Wend
      EndIf
      FileClose($report)
    EndIf

    If $done == 0 Then
      $report = FileOpen($summary, 1)
      If @error == -1 Then
        MsgBox(0, "Error", "Unable to open report log file.")
        Exit(1)
      Else
        FileWriteLine($report,$line & @CRLF)
      EndIf
      FileClose($report)
    EndIf
  Wend
  FileClose($log)
  MsgBox(4096, "Status", "Process complete!")
Else
  MsgBox(4096, "Error", "Unable to open file: " & $source)
EndIf

Also, make sure that you have the latest beta (currently 3.0.94) installed. Some of the earlier builds did have some minor bugs within the looping functions, so this may also be adding to your grief.

Hope this helps!

Share this post


Link to post
Share on other sites

Thanks sooooo much for the help. Also the kind words. It seems like everyone on this forum is soo helpful and it's nice to find a group that is soo willing to help us newbies.


I'd rather laugh with the sinners than cry with the saints..... The sinners are much more fun....Only the good die young. -- Billy Joel

Share this post


Link to post
Share on other sites

That's because all of us were once newbies ourselves. B)

And some of us still are. :whistle:

red

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