Vikramjeet Posted August 16, 2018 Share Posted August 16, 2018 I am a beginner at AutoIt or any code writing. I am trying to copy the last instance of numeric characters in the left side of a log file. Sample text below 99 MOUSE MICKEY AF2 UBX ABC A3E F 0 UB IF NO ZOID ---> This is a sequence number. I may be 1 to 3 digits. (1 Digit -SpaceSpaceDigit, 2 Digit - SpaceDigitDigit, 3 Digit - DigitDigitDigit XX XYZ 100 DUCK DONALD ZOP A4T F 0 M ABCD XTI VE ---> Sequence number 100 needs to be captured in this example VE-XX 0312/SUPER/BS BS /HI/1 /0 UPTO10 CLIENTS DEM-8739081678436 C23 DO-UX 0312/SUPER/ SA /HI/1 /0 DEM-5209617693789 C23 The script will execute a format which will print the above display to a log file. The capture should happen after the above display has been logged My script so far. In the end I want the Until $a = 100 (in my example, which was extracted from the log file) WinActivate("My Application") WinWaitActive("My Application") $file = "C:\Users\Charlie\Desktop\log.txt" ;Log file from where data will be captured $file1 = FileRead($file) Local $a = 0 ;Loop counter variable Do $a += 1 ;Adds 1 to the loop counter Send("INSTANCE " & $a & "{ENTER}") Sleep(1000) ;Waits Until $a = $File1 ;How many times to loop Link to comment Share on other sites More sharing options...
caramen Posted August 16, 2018 Share Posted August 16, 2018 Welcome In this line you need to get the "100" Value ? 100 DUCK DONALD ZOP A4T F 0 M ABCD XTI VE Ps: Plz use Code tool when you post your code My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Vikramjeet Posted August 16, 2018 Author Share Posted August 16, 2018 Correct. 100 is just an example. it could be a number from 1-999. But always the first 3 characters and the last occurrence of numbers in the file. It is not the last line containing text. Thanks Code.au3 Link to comment Share on other sites More sharing options...
Vikramjeet Posted August 16, 2018 Author Share Posted August 16, 2018 WinActivate("My Application") WinWaitActive("My Application") $file = "C:\Users\Charlie\Desktop\log.txt" ;Log file from where data will be captured $file1 = FileRead($file) Local $a = 0 ;Loop counter variable Do $a += 1 ;Adds 1 to the loop counter Send("INSTANCE " & $a & "{ENTER}") Sleep(1000) ;Waits Until $a = $File1 ;How many times to loop Link to comment Share on other sites More sharing options...
caramen Posted August 16, 2018 Share Posted August 16, 2018 (edited) From the help file, a bit modified. #include <MsgBoxConstants.au3> Local $sString = StringLeft("100 This is a sentence with whitespace.", 3) ; Retrieve 3 characters from the left of the string. MsgBox($MB_SYSTEMMODAL, "", "The 3 leftmost characters are: " & $sString) If your text is always with the number in this position. You can do your stuff without an array so its easy. You just do that with your value $file1 Edited August 16, 2018 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Vikramjeet Posted August 16, 2018 Author Share Posted August 16, 2018 123 MOUSE MICKEY AF2 UBX ABC A3E F 0 UB IF NO ZOID XX XYZ 124 MOUSE MINNIE ZOP A4T F 0 M ABCD XTI VE VE-XX 0312/SUPER/BS BS /HI/1 /0 UPTO10 CLIENTS DEM-8739081678436 C23 DO-UX 0312/SUPER/ SA /HI/1 /0 DEM-5209617693789 C23 The data above is not fixed. The sequence number may be a number 1-999. The text also is variable. So irrespective of what data is returned, I want to copy ignore everything and only capture 124 and use it in the loop counter (Execute action 124 times in this example) WinActivate("My Application") WinWaitActive("My Application") $file = "C:\Users\Charlie\Desktop\log.txt" ;Log file from where data will be captured $file1 = FileRead($file) Local $a = 0 ;Loop counter variable Do $a += 1 ;Adds 1 to the loop counter Send("INSTANCE " & $a & "{ENTER}") Sleep(1000) ;Waits Until $a = $File1 ;How many times to loop. If 124 was captured from the log file then i want to run the send command 124 times Link to comment Share on other sites More sharing options...
caramen Posted August 16, 2018 Share Posted August 16, 2018 (edited) your log file can be : 024 ZOULOU BLABLA ZOP A4T F 0 M ABCD XTI VE VE-XX 0312/SUPER/BS BS /HI/1 /0 UPTO10 CLIENTS DEM-8739081678436 C23 DO-UX 0312/SUPER/ SA /HI/1 /0 DEM-5209617693789 C23 And : 009 BLIBLI BLOBLOBLOBLO ZOP A4T F 0 M ABCD XTI VE VE-XX 0312/SUPER/BS BS /HI/1 /0 UPTO10 CLIENTS DEM-8739081678436 C23 DO-UX 0312/SUPER/ SA /HI/1 /0 DEM-5209617693789 C23 Correct ? Everything is random exept the 3 first Characters ? Show more sample of log you can have if I'am mistaking Edited August 16, 2018 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Vikramjeet Posted August 16, 2018 Author Share Posted August 16, 2018 122 TEXT TEXT 123 TEXT TEXT TEXT TEXT TEXT 124 TEXT TEXT TEXT TEXT TEXT TEXT Example of log file Link to comment Share on other sites More sharing options...
Vikramjeet Posted August 16, 2018 Author Share Posted August 16, 2018 Just now, caramen said: your log file can be : 024 ZOULOU BLABLA ZOP A4T F 0 M ABCD XTI VE VE-XX 0312/SUPER/BS BS /HI/1 /0 UPTO10 CLIENTS DEM-8739081678436 C23 DO-UX 0312/SUPER/ SA /HI/1 /0 DEM-5209617693789 C23 009 BLIBLI BLOBLOBLOBLO ZOP A4T F 0 M ABCD XTI VE VE-XX 0312/SUPER/BS BS /HI/1 /0 UPTO10 CLIENTS DEM-8739081678436 C23 DO-UX 0312/SUPER/ SA /HI/1 /0 DEM-5209617693789 C23 Correct ? Everything is random exept the 3 first Characters ? Show more sample of log you can have if I'am mistaking XX XXX 16AUG XXX XXXXX XXXXX ABCDE 1 XXXXXXX XXXX ABCD 01 TES XXXX XXXX 2 XXXXXXXX XXXXXX 0123 XXXXXXXXXXXXXXXX 3 XXXXXX XXXXXX XXXXXXXXXXXX 374 XXXXX XXX XXXX XXXXX 4 XXXXXXXXXX XXXXXXXX 321 CCCC3CCC XXXX XXXXX XXXXXX XXXX 5 SMITH ROLAND BB2 XXXXX XXXXXX XXXXX XXXXX XXXXX XXXX XXX In this example i want to capture the value '5' Link to comment Share on other sites More sharing options...
Vikramjeet Posted August 16, 2018 Author Share Posted August 16, 2018 Just now, Vikramjeet said: XX XXX 16AUG XXX XXXXX XXXXX ABCDE 1 XXXXXXX XXXX ABCD 01 TES XXXX XXXX 2 XXXXXXXX XXXXXX 0123 XXXXXXXXXXXXXXXX 3 XXXXXX XXXXXX XXXXXXXXXXXX 374 XXXXX XXX XXXX XXXXX 4 XXXXXXXXXX XXXXXXXX 321 CCCC3CCC XXXX XXXXX XXXXXX XXXX 5 SMITH ROLAND BB2 XXXXX XXXXXX XXXXX XXXXX XXXXX XXXX XXX In this example i want to capture the value '5' The first characters are always either SpaceSpaceDigit ( 3), SpaceDigitDigit ( 12) or DigitDigitDigit (134) Link to comment Share on other sites More sharing options...
caramen Posted August 16, 2018 Share Posted August 16, 2018 (edited) #include <MsgBoxConstants.au3> #include <String.au3> #include <Array.au3> $File1 = FileRead($File) $aSplit = StringSplit($File1, @CRLF, 3) _ArrayDisplay ($aSplit) $sString = StringLeft($aSplit[0], 3) ; Retrieve 3 characters from the left of the string. MsgBox($MB_SYSTEMMODAL, "", "The 3 leftmost characters are: " & $sString) Work with all these check what you can do Edited August 16, 2018 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Vikramjeet Posted August 16, 2018 Author Share Posted August 16, 2018 12 minutes ago, caramen said: your log file can be : 024 ZOULOU BLABLA ZOP A4T F 0 M ABCD XTI VE VE-XX 0312/SUPER/BS BS /HI/1 /0 UPTO10 CLIENTS DEM-8739081678436 C23 DO-UX 0312/SUPER/ SA /HI/1 /0 DEM-5209617693789 C23 And : 009 BLIBLI BLOBLOBLOBLO ZOP A4T F 0 M ABCD XTI VE VE-XX 0312/SUPER/BS BS /HI/1 /0 UPTO10 CLIENTS DEM-8739081678436 C23 DO-UX 0312/SUPER/ SA /HI/1 /0 DEM-5209617693789 C23 Correct ? Everything is random exept the 3 first Characters ? Show more sample of log you can have if I'am mistaking That is correct. All other data is random. For 1 or 2 digit number in the sequence there are no leading zeros. So 24 will not be 024 but just 24. There is a space before 24 to align right Link to comment Share on other sites More sharing options...
caramen Posted August 16, 2018 Share Posted August 16, 2018 (edited) 22 minutes ago, caramen said: #include <MsgBoxConstants.au3> #include <String.au3> #include <Array.au3> $File1 = FileRead($File) $aSplit = StringSplit($File1, @CRLF, 3) _ArrayDisplay ($aSplit) $sString = StringLeft($aSplit[0], 3) ; Retrieve 3 characters from the left of the string. MsgBox($MB_SYSTEMMODAL, "", "The 3 leftmost characters are: " & $sString) Work with all these check what you can do You can considere " " = 1 character. $sStringBis = " 3" $sStringBeta= StringReplace ($sStringBis, " ", "" ) MsgBox($MB_SYSTEMMODAL, "", "The final String is:_" & $sStringBeta) $sStringAlpha = StringStripWS($sStringBis, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES) MsgBox($MB_SYSTEMMODAL, "", "The final String is:_"&$sStringAlpha) Edited August 16, 2018 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Vikramjeet Posted August 16, 2018 Author Share Posted August 16, 2018 I worked with the attached log file. Also copied below 1- The script read G*L as the 3 letters. Target was "9" 2- I got a pop up message. I do not need a pop up and want 9 to be applied in the number of times the below loop should be performed Do $a += 1 ;Adds 1 to the loop counter Send("INSTANCE " & $a & "{ENTER}") Sleep(1000) ;Waits Until $a = $File1 ;How many times to loop. If 9 was captured from the log file then i want the loop to run 9 times G*L/UX1234/16AUG*S« AS 1234 16AUG XUF 6 1001 322 XAE AE LIST 1 xxxxxx XXXXX I ABC E NB F ET OFL CM PSTZ DOCZ DOCF ET MPR 2 XXXXXX XXXXX S ABC E NB M PST DOCV DOCS ET AP MC 3 XXXXX XXXX T ABC F 0 M ETI 4 XXXXXXX XXXX S ABC E 2 F IB WB PSTC DOCV DOCS ETI AP 5 XXXXXX XXXXX S ABC 2X*E NB F WB ET PSTC DOCV DOCS ETI API 6 XXXXXXX XXXXX I ABC 3X*E 1 M ET PSTC DOCV DOCS ET API MC 7 XXXXX XXX S ABC 4X*E NB M ET PSTC DOCV DOCS ETR APS MS 8 XXXXXXX XXXXX BB2 W ABC 5E*F 4 F IB ET IND IFET CM DOVD SIUR DOCS ETI APP DESD BZXF 9 XXXXXXX XXXXX BB2 W ABC 5F*F 2 M UNED IB FF ET DUKF FOXR ET BA AP t.txt Link to comment Share on other sites More sharing options...
caramen Posted August 16, 2018 Share Posted August 16, 2018 Offcourse becose it's reading [0] Try do to it bro if you work with all my code you can manage that. My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Vikramjeet Posted August 16, 2018 Author Share Posted August 16, 2018 9 was not captured from the log file and the loop was endless WinActivate("My Application") WinWaitActive("My Application") $file = "C:\Users\Charlie\Desktop\t.txt" #include <MsgBoxConstants.au3> #include <String.au3> #include <Array.au3> $File1 = FileRead($File) $aSplit = StringSplit($File1, @CRLF, 3) _ArrayDisplay ($aSplit) $sString = StringLeft($aSplit[0], 3) ; Retrieve 3 characters from the left of the string. MsgBox($MB_SYSTEMMODAL, "", "The 3 leftmost characters are: " & $sString) Local $a = 0 ;Loop counter variable Do $a += 1 ;Adds 1 to the loop counter Send("INSTANCE " & $a & "{ENTER}") Sleep(1000) ;Waits Until $a = $File1 ;How many times to loop Link to comment Share on other sites More sharing options...
caramen Posted August 16, 2018 Share Posted August 16, 2018 (edited) #include <MsgBoxConstants.au3> #include <String.au3> #include <Array.au3> WinActivate("My Application") WinWaitActive("My Application") $file = "C:\Users\Charlie\Desktop\t.txt" ;$file = @ScriptDir &"\T.txt" $File1 = FileRead($File) $aSplit = StringSplit($File1, @CRLF, 3) _ArrayDisplay ($aSplit) $sString = StringLeft($aSplit[20], 3) ; Retrieve 3 characters from the left of the string. MsgBox($MB_SYSTEMMODAL, "", "The 3 leftmost characters are: " & $sString) $sStringBeta= StringReplace ($sString, " ", "" ) Local $a = 0 ;Loop counter variable Do $a += 1 ;Adds 1 to the loop counter Send("INSTANCE " & $a & "{ENTER}") Sleep(1000) ;Waits Until $a = $sStringBeta ;How many times to loop Edited August 16, 2018 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Vikramjeet Posted August 16, 2018 Author Share Posted August 16, 2018 #include <MsgBoxConstants.au3> #include <String.au3> #include <Array.au3> WinActivate("My Application") WinWaitActive("My Application") ;$file = "C:\Users\Charlie\Desktop\t.txt" $file = @ScriptDir &"\T.txt" $File1 = FileRead($File) $aSplit = StringSplit($File1, @CRLF, 3) _ArrayDisplay ($aSplit) $sString = StringLeft($aSplit[20], 3) ; Retrieve 3 characters from the left of the string. MsgBox($MB_SYSTEMMODAL, "", "The 3 leftmost characters are: " & $sString) Local $a = 0 ;Loop counter variable Do $a += 1 ;Adds 1 to the loop counter Send("INSTANCE " & $a & "{ENTER}") Sleep(1000) ;Waits Until $a = $sString ;How many times to loop. MADE THIS CHANGE We are getting there :-) The counter is working. It ran 9 loops. However we are defining to pick first 3 characters on line 20. Line number is not fixed. The script did not read that there is more data after line 20. From the attached log file it should pick 18 t.txt Link to comment Share on other sites More sharing options...
Malkey Posted August 16, 2018 Share Posted August 16, 2018 Try this. #include <MsgBoxConstants.au3> ;$file = "C:\Users\Charlie\Desktop\t.txt" $file = @ScriptDir & "\T.txt" ; The following Reg Exp finds ; the last occurrence of a line (".*" is greedy by default) ; beginning with spaces (if they exist) ("^\h*") ; followed by 1 to 3 digits ("\d{1,3}"). ; Those 1 to 3 digits are captured ("(\d{1,3})"). ; See AutoIt help file for explanations of "(?s)" and "(?m)" PCRE patterns. Explains how "." and "^" are affected. $iNum = StringRegExp(FileRead($file), "(?sm).*^\h*(\d{1,3})", 1)[0] ConsoleWrite($iNum & @CRLF) WinActivate("My Application") Local $hWnd = WinWaitActive("My Application", "", 5) If $hWnd Then For $i = 1 To $iNum Send("INSTANCE " & $i & "{ENTER}") Sleep(1000) ;Waits Next Else MsgBox(0, "", '"My Application" window not found.') EndIf Vikramjeet 1 Link to comment Share on other sites More sharing options...
Vikramjeet Posted August 17, 2018 Author Share Posted August 17, 2018 It is Perfect. It worked flawlessly!!! Exactly what I was trying to achieve. You are a Master :-) Thank You 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