kjreha Posted January 24, 2007 Share Posted January 24, 2007 Hi, I am a newbie. Let me get that out of the way. I have tried doing this several different ways, and I can't seem to get something that works well. I would like to trim this data log extracting only the following tags: ROSPH ROCYL ROAXS RCMP1 RCKA1 RCMP2 RCKA2 RCKDP RCKAV ....repeat with L instead of R. I successfully used _SRE_between to pull data between the tag and the <CR>. However my code fails when the string isn't there. The raw data log may or may not have any of these lines. I will include the code that I got working sofar. But there must be a better way..... please help. Docklight Log File (ASCII) - Started 1/24/2007 12:51:55.45 1/24/2007 12:51:55.79 [TX] - <ENQ> 1/24/2007 12:51:56.12 [TX] - <ENQ> 1/24/2007 12:51:56.15 [RX] - <DC2> 1/24/2007 12:51:56.15 [TX] - <DC2> 1/24/2007 12:52:08.14 [RX] - <SOH>0FA0<STX>RINST Acuitus<CR><LF> MANUF Zeiss Humphrey Systems<CR><LF> MODEL 5015<CR><LF> SFVER A14.2(5)<CR><LF> MDATE 1/24/2007<CR><LF> VERTX 13.50<CR><LF> SEQNO 2<CR><LF> ROSPH -4.00<CR><LF> ROCYL -0.25<CR><LF> ROAXS 71<CR><LF> ROSEQ -0.50<CR><LF> ROSP1 -0.50<CR><LF> ROCY1 -0.25<CR><LF> ROAX1 72<CR><LF> ROSP2 -0.50<CR><LF> ROCY2 -0.25<CR><LF> ROAX2 73<CR><LF> ROSP3 -0.50<CR><LF> ROCY3 -0.25<CR><LF> ROAX3 71<CR><LF> ROSP4 -0.50<CR><LF> ROCY4 -0.25<CR><LF> ROAX4 72<CR><LF> ROSP5 -0.50<CR><LF> ROCY5 -0.25<CR><LF> ROAX5 70<CR><LF> RCMP1 44.75<CR><LF> RCMR1 7.54<CR><LF> RCKA1 11<CR><LF> RCMP2 45.50<CR><LF> RCMR2 7.43<CR><LF> RCKA2 101<CR><LF> RCKDP 0.75<CR><LF> RCKDR 0.11<CR><LF> RCKAV 45.00<CR><LF> RCKAR 7.48<CR><LF> LOSPH -0.50<CR><LF> LOCYL -0.25<CR><LF> LOAXS 33<CR><LF> LOSEQ -0.50<CR><LF> LOSP1 -0.50<CR><LF> LOCY1 -0.25<CR><LF> LOAX1 32<CR><LF> LOSP2 -0.50<CR><LF> LOCY2 -0.25<CR><LF> LOAX2 34<CR><LF> LOSP3 -0.50<CR><LF> LOCY3 -0.25<CR><LF> LOAX3 33<CR><LF> LOSP4 -0.50<CR><LF> LOCY4 -0.25<CR><LF> LOAX4 37<CR><LF> LOSP5 -0.50<CR><LF> LOCY5 -0.25<CR><LF> LOAX5 29<CR><LF> LCMP1 44.75<CR><LF> LCMR1 7.56<CR><LF> LCKA1 175<CR><LF> LCMP2 45.50<CR><LF> LCMR2 7.42<CR><LF> LCKA2 85<CR><LF> LCKDP 0.75<CR><LF> LCKDR 0.14<CR><LF> LCKAV 45.00<CR><LF> LCKAR this is just to take up time before we stop communication so that logging can get everything 1/24/2007 12:52:09.00 [RX] - 1/24/2007 12:52:09.03 [TX] - <ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK> <ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK ><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK><ACK> 1/24/2007 12:52:09.01 [RX] - 7.49<CR><LF> <NUL> Communication stopped by receive sequence "Stop-Communication". Docklight Log File (ASCII) - Stopped 1/24/2007 12:52:10.95 $string = Fileread("C:1_EZeye\acuitis.txt") $arrayROSPH = _SRE_Between ($string, 'ROSPH', '<CR>', 1) $arrayROCYL = _SRE_Between ($string, 'ROCYL', '<CR>', 1) $arrayROAXS = _SRE_Between ($string, 'ROAXS', '<CR>', 1) $arrayRCMP1 = _SRE_Between ($string, 'RCMP1', '<CR>', 1) $arrayRCKA1 = _SRE_Between ($string, 'RCKA1', '<CR>', 1) $arrayRCMP2 = _SRE_Between ($string, 'RCMP2', '<CR>', 1) $arrayRCKA2 = _SRE_Between ($string, 'RCKA2', '<CR>', 1) $arrayRCKDP = _SRE_Between ($string, 'RCKDP', '<CR>', 1) $arrayRCKAV = _SRE_Between ($string, 'RCKAV', '<CR>', 1) $arrayLOSPH = _SRE_Between ($string, 'LOSPH', '<CR>', 1) $arrayLOCYL = _SRE_Between ($string, 'LOCYL', '<CR>', 1) $arrayLOAXS = _SRE_Between ($string, 'LOAXS', '<CR>', 1) $arrayLCMP1 = _SRE_Between ($string, 'LCMP1', '<CR>', 1) $arrayLCKA1 = _SRE_Between ($string, 'LCKA1', '<CR>', 1) $arrayLCMP2 = _SRE_Between ($string, 'LCMP2', '<CR>', 1) $arrayLCKA2 = _SRE_Between ($string, 'LCKA2', '<CR>', 1) $arrayLCKDP = _SRE_Between ($string, 'LCKDP', '<CR>', 1) $arrayLCKAV = _SRE_Between ($string, 'LCKAV', '<CR>', 1) FileWrite ("C:1_EZeye\array.txt",$arrayROSPH[0]&$arrayROCYL[0]&$arrayROAXS[0]&@CRLF&$arrayRCMP1[0]&$arrayRCKA1[0]&@CRLF&$arrayRCMP2[0]&$arrayRCKA2[0]&@CRLF&$arrayRCKDP[0]&@CRLF&$arrayRCKAV[0]&@CRLF&$arrayLOSPH[0]&$arrayLOCYL[0]&$arrayLOAXS[0]&@CRLF&$arrayLCMP1[0]&$arrayLCKA1[0]&@CRLF&$arrayLCMP2[0]&$arrayLCKA2[0]&@CRLF&$arrayLCKDP[0]&@CRLF&$arrayLCKAV[0]) Func _SRE_Between($s_String, $s_Start, $s_End, $i_ReturnArray = 0) ; $i_ReturnArray returns an array of all found if it = 1, otherwise default returns first found $a_Array = StringRegExp($s_String, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3) If Not @error And Not $i_ReturnArray And IsArray($a_Array) Then Return $a_Array[0] If IsArray($a_Array) Then Return $a_Array EndFunc Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 24, 2007 Moderators Share Posted January 24, 2007 (edited) 1. _SRE_Between() is outdated, in 3.2.2.0 there is _StringBetween(). 2. You're not testing to see if the information is an array first before trying to add it. Try this instead of the snippet you provided:#include <string.au3> Local $string = Fileread("C:1_EZeye\acuitis.txt"), $sHoldArray Local $aArraySearch = StringSplit('ROSPH ,ROCYL ,ROAXS ,RCMP1 ,RCKA1 ,RCMP2 ,RCKA2 ,RCKDP ,RCKAV ,LOSPH ,LOCYL ,' & _ 'LOAXS ,LCMP1 ,LCKA1 ,LCMP2 ,LCKA2 ,LCKDP ,LCKAV ', ',') For $iCC = 1 To UBound($aArraySearch) - 1 $aArray = _StringBetween($string, $aArraySearch[$iCC], '\<CR\>', -1, 1) If IsArray($aArray) Then $sHoldArray &= $aArray[0] & @CRLF Next FileWrite(@HomeDrive & "\1_EZeye\array.txt", $sHoldArray)oÝ÷ ØGb´ Ýü¨»§¶Ú$0'!¢w¬ÊrÛ ¢Ö®¶sb6æ6ÇVFRfÇC·7G&æræS2fwC°¤Æö6Âb33c·7G&ærÒfÆW&VBgV÷C´3£ôU¦WRb3#¶7VF2çGBgV÷C²Âb33c·4öÆD'&¤Æö6Âb33c¶'&6V&6Ò7G&æu7ÆBb33µ$õ5Å$ô5ÂÅ$ô2Å$4ÕÅ$4´Å$4Õ"Å$4´"Å$4´EÅ$4´bÄÄõ5ÄÄô5ÂÂb33²fײð b33´Äô2ÄÄ4ÕÄÄ4´ÄÄ4Õ"ÄÄ4´"ÄÄ4´EÄÄ4´bb33²Âb33²Âb33²¤f÷"b33c¶42ÒFòT&÷VæBb33c¶'&6V&6Ò b33c¶'&Òõ7G&æt&WGvVVâb33c·7G&ærÂb33c¶'&6V&6²b33c¶45ÒÂb33²b3#²fÇC´5"b3#²fwC²b33²ÂÓ b4'&b33c¶'&FVâb33c·4öÆD'&f׳Òb33c¶'&6V&6²b33c¶45Òfײb33³Òb33²fײb33c¶'&³Òfײ5$Ä`¤æW@¤fÆUw&FRöÖTG&fRfײgV÷C²b3#³ôU¦WRb3#¶'&çGBgV÷C²Âb33c·4öÆD'& Edited January 24, 2007 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...
Zedna Posted January 24, 2007 Share Posted January 24, 2007 (edited) Use StringSplit and do line by line parsing. Then use _SRE_Between() only for each line.EDIT: SmOke_N was quicker and his solution is better Edited January 24, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
jezzzzy Posted January 24, 2007 Share Posted January 24, 2007 SmOke_N has a nasty habit of doing that. Link to comment Share on other sites More sharing options...
kjreha Posted January 24, 2007 Author Share Posted January 24, 2007 thanks so much for quick responses! It's not pulling any data, though. I even added MsgBox (0, "", $sHoldArray) to see the pulled data. ??? nothing. -Kevin Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 24, 2007 Moderators Share Posted January 24, 2007 thanks so much for quick responses! It's not pulling any data, though. I even added MsgBox (0, "", $sHoldArray) to see the pulled data. ??? nothing.-KevinWorked just fine for me using your information you provided.1. Are you using 3.2.2.0 like I said.2. Are you including #include <string.au3> at the top of your script? 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...
kjreha Posted January 24, 2007 Author Share Posted January 24, 2007 Worked just fine for me using your information you provided.1. Are you using 3.2.2.0 like I said.2. Are you including #include <string.au3> at the top of your script?yes, on both.??? The text file array.txt is just blank ??? Link to comment Share on other sites More sharing options...
herewasplato Posted January 24, 2007 Share Posted January 24, 2007 (edited) maybeFileread("C:1_EZeye\acuitis.txt")should beFileread("C:\1_EZeye\acuitis.txt") Edited January 24, 2007 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
kjreha Posted January 24, 2007 Author Share Posted January 24, 2007 (edited) maybe Fileread("C:1_EZeye\acuitis.txt") should be Fileread("C:\1_EZeye\acuitis.txt")its's fixed!!! here is my final code #include <string.au3> Local $string = Fileread("C:1_EZeye\acuitis.txt"), $sHoldArray Local $aArraySearch = StringSplit("ROSPH ,ROCYL ,ROAXS ,RCMP1 ,RCKA1 ,RCMP2 ,RCKA2 ,RCKDP ,RCKAV ,LOSPH ,LOCYL ,LOAXS ,LCMP1 ,LCKA1 ,LCMP2 ,LCKA2 ,LCKDP ,LCKAV ", ",") For $iCC = 1 To UBound($aArraySearch) - 1 $aArray = _StringBetween($string, $aArraySearch[$iCC], '<CR>', -1, 1) If IsArray($aArray) Then $sHoldArray &= $aArraySearch[$iCC] & '= ' & $aArray[0] & @CRLF Next FileWrite("C:1_EZeye\array.txt", $sHoldArray) Edited January 24, 2007 by kjreha Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 24, 2007 Moderators Share Posted January 24, 2007 its's fixed!!! here is my final code #include <string.au3> Local $string = Fileread("C:1_EZeye\acuitis.txt"), $sHoldArray Local $aArraySearch = StringSplit("ROSPH ,ROCYL ,ROAXS ,RCMP1 ,RCKA1 ,RCMP2 ,RCKA2 ,RCKDP ,RCKAV ,LOSPH ,LOCYL ,LOAXS ,LCMP1 ,LCKA1 ,LCMP2 ,LCKA2 ,LCKDP ,LCKAV ", ",") For $iCC = 1 To UBound($aArraySearch) - 1 $aArray = _StringBetween($string, $aArraySearch[$iCC], '<CR>', -1, 1) If IsArray($aArray) Then $sHoldArray &= $aArraySearch[$iCC] & '= ' & $aArray[0] & @CRLF Next FileWrite("C:1_EZeye\array.txt", $sHoldArray)Your welcome? 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...
herewasplato Posted January 24, 2007 Share Posted January 24, 2007 its's fixed!!! here is my final code......but the code that you posted should not work since you now have an invalid file path in two places. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 24, 2007 Moderators Share Posted January 24, 2007 ...but the code that you posted should not work since you now have an invalid file path in two places.I noticed that on the original... I changed the last one to @HomeDrive & '\' etc... but just realized I didn't change the first one (of course I wasn't using those paths when I tested my own). 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...
kjreha Posted January 25, 2007 Author Share Posted January 25, 2007 I noticed that on the original... I changed the last one to @HomeDrive & '\' etc... but just realized I didn't change the first one (of course I wasn't using those paths when I tested my own).yes, I was tinkering with some of the file paths to get it to work. So the final code was with the paths corrected to C:\.... I think I had a couple tabs open in Scite editor and copied the wrong one.Thanks again for the quick replies.next question though on formatting the way in which the text is written. Instead of the line feed after each item it would be great if it were in this format:ROSPH ROCYL ROAXISRCMP1 RCKA1RCMP2 RCKA2RCKDP RCKAVthen again for L....thanks in advance! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 25, 2007 Moderators Share Posted January 25, 2007 yes, I was tinkering with some of the file paths to get it to work. So the final code was with the paths corrected to C:\.... I think I had a couple tabs open in Scite editor and copied the wrong one.Thanks again for the quick replies.next question though on formatting the way in which the text is written. Instead of the line feed after each item it would be great if it were in this format:ROSPH ROCYL ROAXISRCMP1 RCKA1RCMP2 RCKA2RCKDP RCKAVthen again for L....thanks in advance!What have you tried so far? 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...
Zedna Posted January 25, 2007 Share Posted January 25, 2007 next question though on formatting the way in which the text is written. Instead of the line feed after each item it would be great if it were in this format:ROSPH ROCYL ROAXISRCMP1 RCKA1RCMP2 RCKA2RCKDP RCKAVLook at StringReplace() replace @crlf by space ' ' Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
herewasplato Posted January 25, 2007 Share Posted January 25, 2007 ...I think I had a couple tabs open in Scite editor and copied the wrong one...I may just steal that line :-)I've done the same thing in SciTE.I'm not sure how best to do that formatting - I'll see what others offer for that. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
kjreha Posted January 25, 2007 Author Share Posted January 25, 2007 What have you tried so far?this does what I would like, but it involves multiple Filewrites. Is that OK? I still have to write everything for the left eye. BTW, this is to format findings from an autorefractor at my office (optometrist). Let me know if anyone has a better way. Thanks Smoken for the original code. I just repeated 3 times for what I needed. #include <string.au3> Local $string = Fileread("C:1_EZeye\acuitis.txt"), $sHoldArray1, $sHoldArray2, $sHoldArray3 Local $aArraySearch1 = StringSplit("ROSPH ,ROCYL ,ROAXS ", ",") For $iCC = 1 To UBound($aArraySearch1) - 1 $aArray = _StringBetween($string, $aArraySearch1[$iCC], '<CR>', -1, 1) If IsArray($aArray) Then $sHoldArray1 &= $aArray[0] & " " Next FileWrite("C:1_EZeye\array.txt", $sHoldArray1 & @CRLF) Local $aArraySearch2 = StringSplit("RCMP1 ,RCKA1 ", ",") For $iCC = 1 To UBound($aArraySearch2) - 1 $aArray = _StringBetween($string, $aArraySearch2[$iCC], '<CR>', -1, 1) If IsArray($aArray) Then $sHoldArray2 &= $aArray[0] & " " Next FileWrite("C:1_EZeye\array.txt", $sHoldArray2 & @CRLF) Local $aArraySearch3 = StringSplit("RCMP2 ,RCKA2 ", ",") For $iCC = 1 To UBound($aArraySearch3) - 1 $aArray = _StringBetween($string, $aArraySearch3[$iCC], '<CR>', -1, 1) If IsArray($aArray) Then $sHoldArray3 &= $aArray[0] & " " Next FileWrite("C:1_EZeye\array.txt", $sHoldArray3 & @CRLF) 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