Page 1 of 1

reading lines reverse from file is too slow

Posted: 20 Nov 2017, 16:18
by tardo
Ahoy good sirs.
I'm new to this, had lotsa fun stealing/gluing parts together and somehow it actually works as intended - but..
the most demanding part (below) is super slow reading from a 35 mb .txt
Feels like I've done something horribly wrong, any neat trick to read a few lines in reverse from a big .txt file - faster than 1 min on a ssd? :)
Thankyou!


;read file backwards, print recent lines of interest

#SingleInstance force
Searchstring := "@From"
numberofhits := 0
numberofhitswanted := 12

;count number of lines
FileRead, f1, logs/Client.txt
StringReplace,OutputVar,f1,`n,`n,useerrorlevel
Lines := ErrorLevel + 1

Loop
{
FileReadLine, lastline, logs/Client.txt, %Lines%
if (Lines < 0)
break
Lines := Lines - 1
IfInString, lastline, %Searchstring%
{
messages =: %messages%`n%lastline%
if numberofhits = %numberofhitswanted%
break
numberofhits := numberofhits + 1
}
}

Gui, Add,Edit,ReadOnly, last line number %a_index%`n%messages%`n`nnumber of hits %numberofhits%
Gui, Show
return
GuiClose:
GuiEscape:
ExitApp

;F10::ExitApp

Re: reading lines reverse from file is too slow

Posted: 20 Nov 2017, 16:35
by jeeswg
Omg using FileReadLine on a 35 MB script. Update your script immediately. I've done a script below. Cheers.

Code: Select all

q::
FileRead, vText, % A_ScriptFullPath
oArray := StrSplit(vText, "`n", "`r")
;MsgBox, % oArray.Length()
Loop, % vCount := oArray.Length()
	MsgBox, % vCount " " oArray[vCount--]
return

Re: reading lines reverse from file is too slow

Posted: 20 Nov 2017, 16:56
by Guest
wow yea, that works almost instantly.
TYVM good sir