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=--
searching for text in a fie
Re: searching for text in a fie
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
https://autohotkey.com/board/topic/1481 ... ion-match/
use fileread to read to the file in to a variable
Code: Select all
FileRead, Contents, C:\path\abc.log ; reads the file into a variable
Re: searching for text in a fie
Tested wit a 22MB file. Less than 0.8 seconds execution time.
or even faster
even more fast
Code: Select all
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
}
}
Code: Select all
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
}
}
Code: Select all
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 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Re: searching for text in a fie
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=--
Thanks!
--=kallera=--