Jump to content
Sign in to follow this  
johnjam

Search a text file and write to file in format

Recommended Posts

johnjam

Hello All,

Hope Ive posted in the right place :D

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 :D

#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))

WEnd

myfile.txt


Regards JohnJam

Share this post


Link to post
Share on other sites
Authenticity

Confusing, can you explain it using examples of the desired output or match or what?

Share this post


Link to post
Share on other sites
johnjam

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 :D

The format that Im looking for is in the attached document however this is an msgbox but would like to write to file.txt

Format_of_MSGbox.rtf


Regards JohnJam

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnjam

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

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnjam

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 :D

Regards JohnJam

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×