MyEarth Posted July 3, 2014 Share Posted July 3, 2014 (edited) Hello guys I have a commandline and i need to extract the information in real-temp #include <Constants.au3> Local $foo = Run('mycommand.exe', @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) Local $data While True $data &= StdoutRead($foo) If @error Then ExitLoop ConsoleWrite($data & @CRLF) Sleep(25) WEnd This is a sample output: "(TEXT)","\\TEXT\TEXT\TEXT" "07/03/2014 10:47:55.183","0.000000" "07/03/2014 10:48:06.216","4.122662" "(TEXT)","\\TEXT\TEXT\TEXT" "07/03/2014 10:48:18.788","1.665872" "07/03/2014 10:48:29.558","2.677412" "(TEXT)","\\TEXT\TEXT\TEXT" "07/03/2014 10:48:39.112","0.199651" "(TEXT)","\\TEXT\TEXT\TEXT" If need ony the part with date-time-numbers: "07/03/2014 10:47:55.183","0.000000" And i need to exclude, in addition to other "text", the duplicate lines like: "07/03/2014 10:47:55.183","0.000000" "07/03/2014 10:47:55.183","0.000000" ; <<<<< Remove this Some help? Edited July 3, 2014 by MyEarth Link to comment Share on other sites More sharing options...
Jury Posted July 3, 2014 Share Posted July 3, 2014 #include <Array.au3> $FileOpen = FileOpen(@MyDocumentsDir & '\temp.txt', 0) $FileRead = FileRead($FileOpen) FileClose($FileOpen) $aArray = StringRegExp($FileRead, '(\x22\d{2}/\d{2}/\d{4}\s\d{2}:\d{2}:\d{2}\.\d+\x22,\x22.*?\d\x22)', 3) For $i = 0 To UBound($aArray) - 1 ConsoleWrite($aArray[$i] & @CRLF) Next $aArray = _ArrayUnique($aArray) _ArrayDisplay($aArray) Link to comment Share on other sites More sharing options...
jguinch Posted July 3, 2014 Share Posted July 3, 2014 Or you can try this : Local $sDate = StringRegExpReplace($data, "(?s).*?(\d{2}/\d{2}/\d{4}\h+\d{2}:\d{2}:\d{2}\.\d+)", "$1;") Local $aDate = StringRegExp($sdate, "(\d{2}\/\d{2}\/\d{4}\h+\d{2}:\d{2}:\d{2}\.\d+);(?!.*?\1)", 3) _ArrayDisplay($aDate) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
mikell Posted July 3, 2014 Share Posted July 3, 2014 (edited) #include <Array.au3> $data = '"(TEXT)","\\TEXT\TEXT\TEXT"' & @crlf & _ '"07/03/2014 10:47:55.183","0.000000"' & @crlf & _ '"07/03/2014 10:47:55.183","0.000000"' & @crlf & _ '"07/03/2014 10:48:06.216","4.122662"' & @crlf & _ '"(TEXT)","\\TEXT\TEXT\TEXT"' & @crlf & _ '"07/03/2014 10:48:18.788","1.665872"' & @crlf & _ '"07/03/2014 10:48:29.558","2.677412"' & @crlf & _ '"07/03/2014 10:48:39.112","0.199651"' & @crlf & _ '"(TEXT)","\\TEXT\TEXT\TEXT"' & @crlf & _ '"07/03/2014 10:48:39.112","0.199651"' & @crlf & _ '"07/03/2014 10:48:39.112","0.199651"' $aArray = StringRegExp($data, '(?ms)(^"\d\d/\N+)(?!.*?\1)', 3) _ArrayDisplay($aArray) Edited July 3, 2014 by mikell Link to comment Share on other sites More sharing options...
MyEarth Posted July 3, 2014 Author Share Posted July 3, 2014 (edited) mikell, your version sometime give me "empty" string i think when was TEXTTEXTTEXT: "07/03/2014 16:53:58.368","0.000000" ; here "07/03/2014 16:53:59.441","0.000000" ; here "07/03/2014 16:54:00.451","0.000000" Any way to avoid them? #include <Constants.au3> Local $foo = Run('mycommand.exe', @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) Local $data While True $data &= StdoutRead($foo) If @error Then ExitLoop $aArray = StringRegExp($data, '(?ms)(^"\d\d/\N+)(?!.*?\1)', 3) For $i = 0 To UBound($aArray) - 1 ConsoleWrite($aArray[$i] & @CRLF) Next Sleep(25) WEnd Edited July 3, 2014 by MyEarth Link to comment Share on other sites More sharing options...
mikell Posted July 3, 2014 Share Posted July 3, 2014 Hmm, this regex should return no empty string and I can't manage to reproduce the problem - force it to return an empty string Link to comment Share on other sites More sharing options...
MyEarth Posted July 4, 2014 Author Share Posted July 4, 2014 (edited) So i'll use the super-long-version by Juri, that don't give me any empty string. I have always the problem of "duplicate", i don't want to do an ArrayUnique in a loop of 25ms, i have try something like: If UBound($aArray) >= 1 Then $temp = $aArray[0] For $i = 0 To UBound($aArray) - 1 If $temp <> $aArray[$i] Then ConsoleWrite($aArray[$i] & @CRLF) $temp = $aArray[$i] EndIf Next EndIf But not work, probably the logic is wrong. Suggestion? Edited July 4, 2014 by MyEarth Link to comment Share on other sites More sharing options...
jguinch Posted July 4, 2014 Share Posted July 4, 2014 Did you try my regexp ? #Include <Array.au3> $sOutput = '"(TEXT)","\\TEXT\TEXT\TEXT"' & @CRLF & _ '"07/03/2014 10:47:55.183","0.000000"' & @CRLF & _ '"07/03/2014 10:48:06.216","4.122662"' & @CRLF & _ '"(TEXT)","\\TEXT\TEXT\TEXT"' & @CRLF & _ '"07/03/2014 10:48:18.788","1.665872"' & @CRLF & _ '"07/03/2014 10:48:29.558","2.677412"' & @CRLF & _ '"(TEXT)","\\TEXT\TEXT\TEXT"' & @CRLF & _ '"07/03/2014 10:48:39.112","0.199651"' & @CRLF & _ '"07/03/2014 10:48:39.112","0.199651"' & @CRLF & _ '"07/03/2014 10:48:39.112","0.199651"' & @CRLF & _ '"07/03/2014 10:48:39.112","0.199651"' & @CRLF & _ '"07/03/2014 10:48:39.112","0.199651"' & @CRLF & _ '"(TEXT)","\\TEXT\TEXT\TEXT"' Local $aDate = StringRegExp($sOutput , "(?s)(\d{2}\/\d{2}\/\d{4}\h+\d{2}:\d{2}:\d{2}\.\d+)(?!.*\1)", 3) _ArrayDisplay($aDate) You can also delete duplicates rows with a look like this : #Include <Array.au3> $sOutput = '"(TEXT)","\\TEXT\TEXT\TEXT"' & @CRLF & _ '"07/03/2014 10:47:55.183","0.000000"' & @CRLF & _ '"07/03/2014 10:48:06.216","4.122662"' & @CRLF & _ '"(TEXT)","\\TEXT\TEXT\TEXT"' & @CRLF & _ '"07/03/2014 10:48:18.788","1.665872"' & @CRLF & _ '"07/03/2014 10:48:29.558","2.677412"' & @CRLF & _ '"(TEXT)","\\TEXT\TEXT\TEXT"' & @CRLF & _ '"07/03/2014 10:48:39.112","0.199651"' & @CRLF & _ '"07/03/2014 10:48:39.112","0.199651"' & @CRLF & _ '"07/03/2014 10:48:39.112","0.199651"' & @CRLF & _ '"07/03/2014 10:48:39.112","0.199651"' & @CRLF & _ '"07/03/2014 10:48:39.112","0.199651"' & @CRLF & _ '"(TEXT)","\\TEXT\TEXT\TEXT"' Local $aDate = StringRegExp($sOutput, "(\d{2}\/\d{2}\/\d{4}\h+\d{2}:\d{2}:\d{2}\.\d+)", 3) _ArrayDisplay($aDate) $n = 0 $sTemp = "" For $i = 0 To UBound($aDate) - 1 If NOT StringInStr($sTemp, $aDate[$i]) Then $sTemp &= $aDate[$i] & ";" $n += 1 $aDate[$n - 1] = $aDate[$i] EndIf Next Redim $aDate[$n] _ArrayDisplay($aDate) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
mikell Posted July 4, 2014 Share Posted July 4, 2014 (edited) Eventually try this in case of a N recognition problem $aArray = StringRegExp($data, '(?ms)(^"\d\d/[^\r\n]+)(?!.*?\1)', 3) or this slight adaptation of Juri's one (to check duplicates) $aArray = StringRegExp($data, '(?s)(\x22\d{2}/\d{2}/\d{4}\s\d{2}:\d{2}:\d{2}\.\d+\x22,\x22[.\d]+\x22)(?!.*?\1)', 3) Edited July 4, 2014 by mikell 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