reading lines reverse from file is too slow
Posted: 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
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