gr1fter Posted February 15, 2012 Share Posted February 15, 2012 hello, I have a log file that I am trying to get data from: Bytes : 259.90 m 122.27 m 137.63 m 0 0 0 Bytes : 100.00 m 96 m 137.63 m 0 0 0 Bytes : 3.90 m 2.27 m 137.63 m 0 0 0 Bytes : 59.90 m 122.27 m 137.63 m 0 0 0 Bytes : 200.90 m 32.27 m 137.63 m 0 0 0 Bytes : 350.70 m .27 m 137.63 m 0 0 0 How would i go about reading only the second set of "m" numbers: I want to return from above: 122.27 m 96 m 2.27 m 122.27 m 32.27 m .27 m so far i only been able to read each line using FileReadLine, but i do not know how to read the second set of numbers because the data / spaces is dynamic and never the same so not quite sure how to capture that info. any help would be greatly appreciated. Thanks, Link to comment Share on other sites More sharing options...
jdelaney Posted February 15, 2012 Share Posted February 15, 2012 This works, but there must be better ways to do it ; read in a line $stest = "Bytes : 259.90 m 122.27 m 137.63 m 0 0 0" ; split on the 'm' $asTest = stringsplit ( $stest, "m" ) ; use the second $sNeededString = StringReplace ( $asTest[2], " ", "" ) & " m" ; display msgbox ( 4096, "test", $sNeededString ) IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Developers Jos Posted February 15, 2012 Developers Share Posted February 15, 2012 Something like this: Global $INPUT[6] = ["259.90 m 122.27 m 137.63 m 0 0 0","100.00 m 96 m 137.63 m 0 0 0","3.90 m 2.27 m 137.63 m 0 0 0","59.90 m 122.27 m 137.63 m 0 0 0","200.90 m 32.27 m 137.63 m 0 0 0","350.70 m .27 m 137.63 m 0 0 0"] For $X = 0 To UBound($INPUT)-1 ConsoleWrite($x & " Record:" & $INPUT[$x] & @crlf) $Result = StringRegExp($INPUT[$x],"(.*?)m",3) ConsoleWrite(" Result:") For $i = 0 To UBound($Result) - 1 ConsoleWrite($i & "=" & $Result[$i] & " ") Next ConsoleWrite(@CRLF) ConsoleWrite(@CRLF) Next SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
BrewManNH Posted February 15, 2012 Share Posted February 15, 2012 Here's my entry $File = FileOpen("text.txt") ; change to your file name While 1 $Text = FileReadLine($File) If @error = -1 Then ExitLoop $Start = StringInStr($Text, "m") $Text2 = StringMid($Text, $Start + 2, StringInStr($Text, "m", 0, 2) - $Start) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Text2 = ' & $Text2 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console WEnd If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Guest Posted February 15, 2012 Share Posted February 15, 2012 (edited) This is the best way. #include <Array.au3> $Itext = "Bytes : 259.90 m 122.27 m 137.63 m 0 0 0" & @CRLF & _ "Bytes : 100.00 m 96 m 137.63 m 0 0 0" & @CRLF & _ "Bytes : 3.90 m 2.27 m 137.63 m 0 0 0" & @CRLF & _ "Bytes : 59.90 m 122.27 m 137.63 m 0 0 0" & @CRLF & _ "Bytes : 200.90 m 32.27 m 137.63 m 0 0 0" & @CRLF & _ "Bytes : 350.70 m .27 m 137.63 m 0 0 0" $FFFF = StringRegExp($Itext, '(?i)Bytes : .*?m(.*?m)', 3) _ArrayDisplay($FFFF) If you want to read from a file use the below code. #include <Array.au3> $Text = FileRead(@ScriptDir&"logN.txt") $FFFF = StringRegExp($Text, '(?i)Bytes : .*?m(.*?m)', 3) _ArrayDisplay($FFFF) Edited February 15, 2012 by Guest Link to comment Share on other sites More sharing options...
BrewManNH Posted February 15, 2012 Share Posted February 15, 2012 This is the best way. #include <Array.au3> $Itext = "Bytes : 259.90 m 122.27 m 137.63 m 0 0 0" & @CRLF & _ "Bytes : 100.00 m 96 m 137.63 m 0 0 0" & @CRLF & _ "Bytes : 3.90 m 2.27 m 137.63 m 0 0 0" & @CRLF & _ "Bytes : 59.90 m 122.27 m 137.63 m 0 0 0" & @CRLF & _ "Bytes : 200.90 m 32.27 m 137.63 m 0 0 0" & @CRLF & _ "Bytes : 350.70 m .27 m 137.63 m 0 0 0" $FFFF = StringRegExp($Itext, '(?i)Bytes : .*?m(.*?)m', 3) _ArrayDisplay($FFFF) Why is that the "best" way? If all of the ways work equally that is. jdelaney 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Guest Posted February 15, 2012 Share Posted February 15, 2012 Why is that the "best" way? If all of the ways work equally that is.Because it is the cleanest. Link to comment Share on other sites More sharing options...
BrewManNH Posted February 15, 2012 Share Posted February 15, 2012 Because it is the cleanest. Define cleanest, because that's an ambiguous phrase that means nothing out of context. I know my method will be slower due to reading from a file, but using the other codes and reading from the same file, the speeds are relatively the same rather than pre-loading the array/string in the script. So, it's not a question of speed in this case. So I was curious as to what the "best" and "cleanest" mean in the context of code. Yes, it's one line compared to several, but that one line still takes just as long as reading a line at a time. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Guest Posted February 15, 2012 Share Posted February 15, 2012 Define cleanest, because that's an ambiguous phrase that means nothing out of context.I know my method will be slower due to reading from a file, but using the other codes and reading from the same file, the speeds are relatively the same rather than pre-loading the array/string in the script. So, it's not a question of speed in this case. So I was curious as to what the "best" and "cleanest" mean in the context of code. Yes, it's one line compared to several, but that one line still takes just as long as reading a line at a time.I don't understand what is your problem with me. But let me define you what i meant my the "Best", is that my code is fast when it comes to parsing data.I also did a benchmark to show you how long does it take to return the result.0.345295005587713 MS (My Code)0.55480508330242 MS (Your Code)And now lets go on what is meant by "cleanest". If i compare the code you will see that its just one line and this is what the StringRegExp was designed for, you have been on this forum long enough therefore why ask a silly question. Link to comment Share on other sites More sharing options...
Developers Jos Posted February 15, 2012 Developers Share Posted February 15, 2012 I don't understand what is your problem with me. But let me define you what i meant my the "Best", is that my code is fast when it comes to parsing data.Let me take a stab at that: You are showing an attitude with the statements made that work as a red clot.Anyway, this is the last off topic post in this thread and think the OP has ample info to go on. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 15, 2012 Moderators Share Posted February 15, 2012 I don't thiink the question was silly, personally. At the risk of hijacking the OP's thread with this back and forth, I think it can be agreed by all that there are many ways to do things with AutoIT. A difference of .2ms doesn't make me <facepalm> as opposed to BrewMan's code. I wouldn't go throwing "my code is best" around too much in this forum "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
gr1fter Posted February 15, 2012 Author Share Posted February 15, 2012 Thanks for all the replies! I do believe I have enough info to get me on my way, I work more on this tomorrow. Thanks again! 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