searching for text in a fie

Get help with using AutoHotkey and its commands and hotkeys
kallera
Posts: 17
Joined: 24 Sep 2017, 20:35

searching for text in a fie

26 Apr 2018, 17:36

Hi everybody,

I have stumbled upon an issue where i desperately need some help. I need to find whether a string (for example the string "belzebub") can be found in a fairly big (atm about 20Meg file abc.log) on my disk. I know that the text is, if it is, among the last f.ex. 1000 bytes. No other occurancies are relevant but the last occurance.

So somehing like this:

found := 0
open file C:\path\abc.log/ re-read file the file abc ; re-read the file because the text, if it exists has been added fairly recently by another program
read from the end of the file
read last 1000 bytes
search for the text ”belzebub” in the last bytes searching from the end
if the text is found
{
found_pos := position ; mark position where was found
found := 1 ; mark that text was found
return
}
return ; nothing was found, all is done

Could somebody point me in the right direction? Any help would be appreciated. Which commands are necessary when opening / re-reading the file, how to tell the program where it should be read, how to search for the text, all this in to say the least unclear to me.

Thank you.

--=kallera=--
Rindis
Posts: 202
Joined: 23 Dec 2013, 13:58
Location: Norway

Re: searching for text in a fie

27 Apr 2018, 02:06

This would be where you start looking for a solution
https://autohotkey.com/board/topic/1481 ... ion-match/



use fileread to read to the file in to a variable

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

FileRead, Contents, C:\path\abc.log ; reads the file into a variable
Odlanir
Posts: 274
Joined: 20 Oct 2016, 08:20

Re: searching for text in a fie

27 Apr 2018, 08:34

Tested wit a 22MB file. Less than 0.8 seconds execution time.

Code: [Select all] [Download] GeSHi © Codebox Plus

FileRead, all, abc.log
arr := strsplit(all, "`n")
loop, % arr.MaxIndex() {
if (RegExMatch(arr[a_index], "belzebub")) {
MsgBox % "Found at line : " a_index "`nRow contents`n" arr[a_index]
break
}
}

or even faster

Code: [Select all] [Download] GeSHi © Codebox Plus

FileRead, all, abc.log
loop, parse, all, `n, `r
{
if (RegExMatch(A_LoopField, "belzebub")) {
MsgBox % "Found at line : " a_index "`nRow contents`n" A_LoopField
break
}
}

even more fast

Code: [Select all] [Download] GeSHi © Codebox Plus

FileRead, all, abc.log
loop, parse, all, `n, `r
{
IfInString, A_LoopField, belzebub
{
MsgBox % "Found at line : " a_index "`nRow contents`n" A_LoopField
break
}
}
____________________________________________________________________________
Windows 7 Home Premium 64 bit - Autohotkey v1.1.24.02 64-bit Unicode
kallera
Posts: 17
Joined: 24 Sep 2017, 20:35

Re: searching for text in a fie

27 Apr 2018, 22:30

Thank you both Rindis and Odlanir very much for your kind help and for the trouble you had answering my request for help! It was highly appreciated. I will test the solutions you suggested as soon as possible and return with more questions as needed.

Thanks!

--=kallera=--

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 81 guests