dodger42 Posted August 4, 2006 Share Posted August 4, 2006 (edited) I have a log file I am processing. For some reason it doesn't seem to be yielding correct results (the messagebox spits out incorrect results). Here are the logfile lines: 01/13:26:24 BLUE "Woody25"(A-10A) kill vehicle RED "ZSU-23-4 Shilka" by AGM-65D Maverick 01/13:27:02 BLUE "Woody25"(A-10A) kill vehicle RED "Tor 9A331" by AGM-65D Maverick 01/13:44:12 BLUE "Woody25"(A-10A) kill vehicle RED "BMD-1" by AGM-65K Maverick 01/13:57:50 BLUE "S77th-KonKuSSioN"(A-10A) kill ship RED "Elnya" by AGM-65D Maverick 01/13:46:18 RED "169th_Fudd"(Su-25T) kill vehicle BLUE "Roland rdr" by Kh-58 (AS-11 Kilter) Here is the script: expandcollapse popup#include <file.au3> Dim $aRecords Global $logfile = "./split.txt" Global $bluekills Global $redkills If Not _FileReadToArray("mp_log.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $bluekills = 0 $redkills = 0 $filehandle = FileOpen($logfile, 1) If $filehandle = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf For $x = 1 to $aRecords[0] ;Msgbox(0,'Lines:', $aRecords[0]) sleep(100) $string = StringSplit ( $aRecords[$x], " ", ) For $i = 1 to $string[0] FileWriteLine($filehandle, " string:" & $string[$i]) Next If $string[$x] > 0 Then If $string[2] <> $string[6] and $string[5] = "vehicle" and $string[4] = "kill" Then If $string[2] = "BLUE" Then $bluekills = $bluekills + 1 Elseif $string[2] = "RED" Then $redkills = $redkills + 1 EndIf EndIf Next Msgbox(0,'RedKills:', $redkills) Msgbox(0,'BlueKills:', $bluekills) FileClose($filehandle) Any suggestion?? Edited August 4, 2006 by dodger42 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 4, 2006 Moderators Share Posted August 4, 2006 (edited) This needs Beta, but if I'm understanding your question/task, this all you need:Local $aString = _SRE_BetweenEX(@DesktopDir & '\Test.txt', 'kill vehicle ', '"') Local $RedCount, $BlueCount For $iCount = 0 To UBound($aString) - 1 If StringInStr($aString[$iCount], 'Red') Then $RedCount += 1 Else $BlueCount += 1 EndIf Next MsgBox(64, 'Info:', 'Red Count = ' & $RedCount & @CR & 'Blue Count = ' & $BlueCount) Func _SRE_BetweenEX($s_FilePath, $s_Start, $s_End) $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath)) $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3) If IsArray($a_Array) Then Return $a_Array EndFuncoÝ÷ ØGbµ8b³ .Ü(®Kh¡«¢+Ù1½°ÀÌØíI ½Õ¹Ðô}MI}IÑÕɹ ½Õ¹Ð¡ÍѽÁ¥ÈµÀìÌäìÀäÈíQÍйÑáÐÌäì°Ìäí¥±°Ù¡¥±IÌäì¤)1½°ÀÌØí ±Õ ½Õ¹Ðô}MI}IÑÕɹ ½Õ¹Ð¡ÍѽÁ¥ÈµÀìÌäìÀäÈíQÍйÑáÐÌäì°Ìäí¥±°Ù¡¥± 1UÌäì¤)5Í ½à ØаÌäí%¹¼èÌäì°ÌäíI ½Õ¹ÐôÌäìµÀìÀÌØíI ½Õ¹ÐµÀì HµÀìÌäí ±Õ ½Õ¹ÐôÌäìµÀìÀÌØí ±Õ ½Õ¹Ð¤()Õ¹}MI}IÑÕɹ ½Õ¹Ð ÀÌØíÍ}¥±AÑ °ÀÌØíÍMÑÉ¥¹¤($ÀÌØí¡}Iô¥±I ÀÌØíÍ}¥±AÑ °¥±ÑM¥é ÀÌØíÍ}¥±AÑ ¤¤(%MÑÉ¥¹IÁ± ÀÌØí¡}I°ÀÌØíÍMÑÉ¥¹°ÌäìÌäì¤(%IÑÕɸáѹ)¹Õ¹ Edited August 4, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
dodger42 Posted August 4, 2006 Author Share Posted August 4, 2006 Got it sorted using some SELECT CASE stuff instead. Thanks Link to comment Share on other sites More sharing options...
dodger42 Posted August 4, 2006 Author Share Posted August 4, 2006 Thanks SmokeN, though I'm certain your code works, its kinda hard for me to follow (due my inexperience). Will give it a shot though! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 4, 2006 Moderators Share Posted August 4, 2006 (edited) Thanks SmokeN, though I'm certain your code works, its kinda hard for me to follow (due my inexperience). Will give it a shot though!If you run either example and just replace the file your going to be reading that has your information, it will return the same thing that all those other lines of code your currently using does. Edit: You could even do it with UBound and StringSplit() ... Local $RedCount = _SR_ReturnCount(@DesktopDir & '\Test.txt', 'kill vehicle RED') Local $BlueCount = _SR_ReturnCount(@DesktopDir & '\Test.txt', 'kill vehicle BLUE') MsgBox(64, 'Info:', 'Red Count = ' & $RedCount & @CR & 'Blue Count = ' & $BlueCount) Func _SR_ReturnCount($s_FilePath, $sString) Return UBound(StringSplit(FileRead($s_FilePath), $sString, 1)) - 2 EndFunc Edited August 4, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
bluebearr Posted August 4, 2006 Share Posted August 4, 2006 I thought that it might be instructive to find what was wrong in the orignal script, so I played with it. I've marked my changes. expandcollapse popup#include <file.au3> Dim $aRecords Global $logfile = "./split.txt" Global $bluekills Global $redkills If Not _FileReadToArray("mp_log.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $bluekills = 0 $redkills = 0 $filehandle = FileOpen($logfile, 1) If $filehandle = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf For $x = 1 to $aRecords[0] ;Msgbox(0,'Lines:', $aRecords[0]) sleep(100) $string = StringSplit ( $aRecords[$x], " " ) ; BB: Removed extra comma For $i = 1 to $string[0] FileWriteLine($filehandle, " string:" & $string[$i]) Next If $string[0] > 5 Then ; BB: **MAIN CHANGE** Changed test If $string[2] <> $string[6] and $string[5] = "vehicle" and $string[4] = "kill" Then If $string[2] = "BLUE" Then $bluekills = $bluekills + 1 ElseIf $string[2] = "RED" Then $redkills = $redkills + 1 ; BB: Moved statement to own line because Scite complained otherwise EndIf ; BB: Added EndIf EndIf Next Msgbox(0,'RedKills:', $redkills) Msgbox(0,'BlueKills:', $bluekills) FileClose($filehandle) BlueBearrOddly enough, this is what I do for fun. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now