reading lines reverse from file is too slow Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tardo

reading lines reverse from file is too slow

20 Nov 2017, 16:18

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
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: reading lines reverse from file is too slow

20 Nov 2017, 16:35

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
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: segolore and 327 guests