johnjam Posted June 24, 2009 Posted June 24, 2009 Hello All, Hope Ive posted in the right place Ive been searching the forums for a couple of days now and although a little succesful with the slightly modified script found on the forums it doesnt do exactly what I want so I'd like to enlist a little help if possible. I have a text file from a web site. which I would like to search for more than one keyword currently it searches one at the moment. I have tried other scripts that search more keywords. The below script gives me a start pos and end pos that displays to msgbox in the format that im looking for, However i would like to write this to file.txt in the same format so that i can then inject to a database. possibly better ideas welcome here. Is this possible my tries have ended up with writing this post and scratching my head. I have been through the help file and StringRegExp makes for some heavy bed time reading amoungst other commands found for searching a text file in the format that Im looking for Thanks In advance #include<IE.au3> #include <File.au3> Opt("WinWaitDelay", 100) Opt("WinTitleMatchMode", 3) Opt("WinDetectHiddenText", 1) Opt("MouseCoordMode", 0) Local $sLogText = FileRead("c:\capture\myfile.txt") Local $sSearchText = "SearchCriteria" local $i = 1 local $pos, $startpos, $temp, $endpos while 1 $pos = StringInStr($sLogText, $sSearchText, 0, $i) if $pos = 0 then ExitLoop $startpos = StringInStr(StringLeft($sLogText, $pos), "proposal", 0, -1) $temp = StringInStr(StringTrimLeft($sLogText, $pos), "proposal") if $temp = 0 Then $endpos = StringLen($sLogText) else $endpos = $pos + $temp EndIf $i += 1 MsgBox(0,"Entry found", StringMid($sLogText, $startpos, $endpos - $startpos)) WEndmyfile.txt Regards JohnJam
Authenticity Posted June 24, 2009 Posted June 24, 2009 Confusing, can you explain it using examples of the desired output or match or what?
johnjam Posted June 24, 2009 Author Posted June 24, 2009 Confusing, can you explain it using examples of the desired output or match or what?Thanks for the reply Authenticity Sorry if it looks confused The format that Im looking for is in the attached document however this is an msgbox but would like to write to file.txtFormat_of_MSGbox.rtf Regards JohnJam
water Posted June 24, 2009 Posted June 24, 2009 If I understand what you mean simply replace MsgBox(0,"Entry found", StringMid($sLogText, $startpos, $endpos - $startpos))oÝ÷ Û«¢+Ù¥±]É¥Ñ ÅÕ½ÐíèÀäÈíѵÀÀäÈí½ÕÑÁÕйÑáÐÅÕ½Ðì°MÑÉ¥¹5¥ ÀÌØíÍ1½QáаÀÌØíÍÑÉÑÁ½Ì°ÀÌØí¹Á½Ì´ÀÌØíÍÑÉÑÁ½Ì¤¤ My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
johnjam Posted June 24, 2009 Author Posted June 24, 2009 If I understand what you mean simply replace MsgBox(0,"Entry found", StringMid($sLogText, $startpos, $endpos - $startpos))oÝ÷ Û«¢+Ù¥±]É¥Ñ ÅÕ½ÐíèÀäÈíѵÀÀäÈí½ÕÑÁÕйÑáÐÅÕ½Ðì°MÑÉ¥¹5¥ ÀÌØíÍ1½QáаÀÌØíÍÑÉÑÁ½Ì°ÀÌØí¹Á½Ì´ÀÌØíÍÑÉÑÁ½Ì¤¤Thanks for the reply water I have been trying that and came up with an error in the script however, I must have made a typo somewhere along the lines as I have just tried your snippet of code and works great. Thanks for the help with this. Simple really. where i went wrong with this i dont know Thanks once again One question still exists can i get the script to search on more keywords Regards JohnJam
water Posted June 24, 2009 Posted June 24, 2009 Some more questions:How many different keywords would you like to search for? 2, 3, undefined (to be entered by user)?How would you like to present the results? First all findings of keyword 1, then all findings of keyword 2 ...What do you want to present? Position of each finding in file; number of findings for keyword 1, keyword 2; sum of all findings ... My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
johnjam Posted June 24, 2009 Author Posted June 24, 2009 Some more questions:How many different keywords would you like to search for? 2, 3, undefined (to be entered by user)?How would you like to present the results? First all findings of keyword 1, then all findings of keyword 2 ...What do you want to present? Position of each finding in file; number of findings for keyword 1, keyword 2; sum of all findings ...I have sorted this Many thanks to Authenticity and water for the help Regards JohnJam
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