Jump to content

Search a text file and write to file in format


Recommended Posts

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

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...