mentosan Posted September 12, 2008 Share Posted September 12, 2008 Hi! I'm having the content of this txt file. The first part is a timestamp, the second part (after | ) represents numbers of tasks : 12:00:07 | 60 12:00:07 | 60 12:00:17 | 60 12:00:17 | 60 12:00:27 | 0 12:00:27 | 0 12:00:37 | 0 12:00:37 | 0 12:00:48 | 0 12:00:48 | 0 12:00:58 | 0 12:00:58 | 0 12:01:08 | 0 12:01:08 | 0 12:01:18 | 0 12:01:18 | 0 12:01:28 | 0 12:01:28 | 0 12:01:38 | 0 12:01:39 | 0 12:01:49 | 0 12:01:49 | 0 12:01:59 | 0 12:01:59 | 0 12:02:09 | 0 12:02:09 | 0 12:02:19 | 0 12:03:17 | 14 12:03:17 | 14 12:03:31 | 14 12:03:31 | 14 ........ I only want to keep one line for each minute (preferably the first lines,when the minutes digit is changed), so the result would be : 12:00:07 | 60 12:01:08 | 0 12:02:09 | 0 12:03:17 | 14 Any ideas ? Thx Link to comment Share on other sites More sharing options...
andybiochem Posted September 12, 2008 Share Posted September 12, 2008 (edited) Hi,Here's an example of how I might do this.#include <Array.au3> #include <File.au3> ;----- Read file to an array ----- Dim $aArray[1] _FileReadToArray("data.txt",$aArray) ;----- create an empty 'loading' string ----- $sString = "" ;----- go throught the time stamps in the array ----- For $i = 1 to (UBound($aArray) - 1) $sMinCurrent = StringMid($aArray[$i],4,2);get current minutes $sMinPrevious = StringMid($aArray[$i - 1],4,2);get previous minutes If $sMinCurrent <> $sMinPrevious Then $sString &= $aArray[$i] & ",";check to see if change in time, and add to string Next ;----- split 'loading' string back to an array ----- $aArray = StringSplit(StringTrimRight($sString,1),",") If $sString = "" Then Dim $aArray[1];if no items found, dim out the array ;----- show new array ----- _ArrayDisplay($aArray,"",-1,0,"¬")Note that you said you wanted "preferably the first lines", well this example will only ever keep the first lines.....it looks for a change in timestamp minutes and keeps the change.Let me know if this helps![EDIT] oops, didn't read the question properly, fixed code Edited September 12, 2008 by andybiochem - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 12, 2008 Moderators Share Posted September 12, 2008 (edited) Local $s_text = ClipGet(); FileRead("Log.txt") Local $a_sre = StringRegExp($s_text, "(\d+:(\d+):\d+.+?)(?:\r|\z)", 3) If @error Then Exit Local $s_values, $s_hold For $i = 0 To UBound($a_sre) -1 Step 2 If StringInStr("," & $s_values & ",", "," & $a_sre[$i + 1] & ",") = 0 Then $s_hold &= $a_sre[$i] & @CRLF $s_values &= $a_sre[$i + 1] & "," EndIf Next MsgBox(0, 0, $s_hold) Edited September 12, 2008 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...
mentosan Posted September 12, 2008 Author Share Posted September 12, 2008 @ andybiochem: It is working ! Thanks a lot ! @ SmOke_N : Thank you for the code, but it is not ok Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 12, 2008 Moderators Share Posted September 12, 2008 (edited) @ andybiochem: It is working ! Thanks a lot ! @ SmOke_N : Thank you for the code, but it is not okThat's funny, seems to work just fine with what you provided expandcollapse popupLocal $s_text = "12:00:07 | 60" & @CRLF $s_text &= "12:00:07 | 60" & @CRLF $s_text &= "12:00:17 | 60" & @CRLF $s_text &= "12:00:17 | 60" & @CRLF $s_text &= "12:00:27 | 0" & @CRLF $s_text &= "12:00:27 | 0" & @CRLF $s_text &= "12:00:37 | 0" & @CRLF $s_text &= "12:00:37 | 0" & @CRLF $s_text &= "12:00:48 | 0" & @CRLF $s_text &= "12:00:48 | 0" & @CRLF $s_text &= "12:00:58 | 0" & @CRLF $s_text &= "12:00:58 | 0" & @CRLF $s_text &= "12:01:08 | 0" & @CRLF $s_text &= "12:01:08 | 0" & @CRLF $s_text &= "12:01:18 | 0" & @CRLF $s_text &= "12:01:18 | 0" & @CRLF $s_text &= "12:01:28 | 0" & @CRLF $s_text &= "12:01:28 | 0" & @CRLF $s_text &= "12:01:38 | 0" & @CRLF $s_text &= "12:01:39 | 0" & @CRLF $s_text &= "12:01:49 | 0" & @CRLF $s_text &= "12:01:49 | 0" & @CRLF $s_text &= "12:01:59 | 0" & @CRLF $s_text &= "12:01:59 | 0" & @CRLF $s_text &= "12:02:09 | 0" & @CRLF $s_text &= "12:02:09 | 0" & @CRLF $s_text &= "12:02:19 | 0" & @CRLF $s_text &= "12:03:17 | 14" & @CRLF $s_text &= "12:03:17 | 14" & @CRLF $s_text &= "12:03:31 | 14" & @CRLF $s_text &= "12:03:31 | 14" Local $a_sre = StringRegExp($s_text, "(\d+:(\d+):\d+.+?)(?:\r|\z)", 3) If @error Then Exit Local $s_values, $s_hold For $i = 0 To UBound($a_sre) -1 Step 2 If StringInStr("," & $s_values & ",", "," & $a_sre[$i + 1] & ",") = 0 Then $s_hold &= $a_sre[$i] & @CRLF $s_values &= $a_sre[$i + 1] & "," EndIf Next MsgBox(0, 0, $s_hold) Edited September 12, 2008 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...
andybiochem Posted September 12, 2008 Share Posted September 12, 2008 No probs!Although, I agree that SmOke_N's approach using Regular Expressions would be more robust.My method relies on consistency in your timestamp reporting, and will fail if there's ever a deviation from that.It's always better to try to account for future problems/changes by using something like regular expression.All the best. - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
mentosan Posted September 12, 2008 Author Share Posted September 12, 2008 @ SmOke_N : I don't find the output file/window. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 12, 2008 Moderators Share Posted September 12, 2008 @ SmOke_N : I don't find the output file/window.No idea what you're saying there. The example I provided works on its own as I've shown. It's up to you to replace $s_text = "etc" with $s_text = FileRead(Filename). 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...
mentosan Posted September 12, 2008 Author Share Posted September 12, 2008 OK, it's ok now SmOke_N. I was doing some different tasks in the same time, that's why I haven't checked more closely your code. After I replaced the $s_text with the name of my file it was working. Still ,I prefer to use andybiochem's code because the result can by copied to the clipboard. Maybe later, when the time is my friend, I will try to adapt his code to your, to have the option of copy to clipboard. Thank you both for support ! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 14, 2008 Moderators Share Posted September 14, 2008 OK, it's ok now SmOke_N. I was doing some different tasks in the same time, that's why I haven't checked more closely your code. After I replaced the $s_text with the name of my file it was working. Still ,I prefer to use andybiochem's code because the result can by copied to the clipboard. Maybe later, when the time is my friend, I will try to adapt his code to your, to have the option of copy to clipboard. Thank you both for support !If all you wanted to do was copy the results to a clipboard. Replace: MsgBox(0, 0, $s_hold) With: ClipPut($s_hold) 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...
mentosan Posted September 15, 2008 Author Share Posted September 15, 2008 Thank you SmOke_N ! 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