Code: Select all
Loop, Read, D:\0.log
{
Line := A_LoopReadLine
Lines .= Lines"`n"Line ; but ignore all lines except for the last 50 !
}
Code: Select all
Loop, Read, D:\0.log
{
Line := A_LoopReadLine
Lines .= Lines"`n"Line ; but ignore all lines except for the last 50 !
}
Code: Select all
FilePath := "D:\0.log"
Loop, Read,% FilePath
Total_Line := A_Index
StartLine := Total_Line - 50
Loop, Read, % FilePath
if (A_Index > StartLine)
Lines .= A_LoopReadLine "`n"
MsgBox, % Lines
Code: Select all
FileRead, logLines, D:\0.log
lines := LastLines(logLines, 50)
LastLines(ByRef string, linecount, delimiter := "`n") {
return SubStr(string, InStr(string, delimiter,, 0, linecount) + StrLen(delimiter))
}
That omits the first n lines instead of returning the last n lines...Xtra wrote: ↑24 Aug 2021, 02:58Code: Select all
FileRead, logLines, D:\0.log lines := LastLines(logLines, 50) LastLines(ByRef string, linecount, delimiter := "`n") { return SubStr(string, InStr(string, delimiter,, 0, linecount) + StrLen(delimiter)) }
If the files are not VERY big (bigger than the available memory), it is much more efficient to read the entire file into memory and then remove the starting linesSpark wrote: ↑24 Aug 2021, 02:41Hello,
Try This
Code: Select all
FilePath := "D:\0.log" Loop, Read,% FilePath Total_Line := A_Index StartLine := Total_Line - 50 Loop, Read, % FilePath if (A_Index > StartLine) Lines .= A_LoopReadLine "`n" MsgBox, % Lines
Code: Select all
fileread, text, %Filepath%
startpos:=instr(text,"`n",,-1,50)+1
text:=substr(text, startpos)
Code: Select all
Loop, parse, text, `n, `r
{
Line := A_LoopField
}
Code: Select all
FileReadLastLines(FileName, LastLines := 5, Delim := "`n")
{
if (IsObject(file := FileOpen(FileName, "r-d", "UTF-8"))) {
CountLines := 0
Loop % file.Length {
file.Seek("-" . i := A_Index)
if (file.Read(1) = Delim)
if (++CountLines = LastLines)
break
}
file.Seek("-" . i)
return LTrim(file.Read(), Delim), file.Close()
}
return false
}