SOLVED: Latest 10 lines of a variable

Get help with using AutoHotkey and its commands and hotkeys
ozzii
Posts: 343
Joined: 30 Oct 2013, 06:04

SOLVED: Latest 10 lines of a variable

13 Oct 2014, 07:45

Hi,
I have this.

Code: Select all

Loop, Parse, FileContents, `n, `r
{
	If (InStr(A_LoopField, TEXT, CaseSensitive = false))
	{
		StringSplit, FIND, A_LoopField, ~
		RESULTAT .= FIND6 "`n"
	}
}
Now I would like to show just the latest 10 lines of RESULTAT.

How can I do that?
Is there something like loop - parse - maxindex?

Thanks in advance.
Last edited by ozzii on 16 Oct 2014, 02:51, edited 1 time in total.
User avatar
jNizM
Posts: 2613
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Latest 10 lines of a variable

13 Oct 2014, 08:07

store every Line in an array and use arrTest.MaxIndex()
[AHK] 1.1.32.00 x64 Unicode | [WIN] 10 Pro (Version 2004) x64 | [GitHub] Profile
Donations are appreciated if I could help you
ahcahc
Posts: 110
Joined: 25 Jul 2014, 23:55

Re: Latest 10 lines of a variable

13 Oct 2014, 08:27

MsgBox % last10 := RegExReplace(RESULTAT,"`as).*?((?:(?:\V+)?\R){9}\V+$)","$1")
Your last line will always be blank. You can use trim to remove the last linefeed RegExReplace(trim(RESULTAT,"`n"),"`as).*?((?:(?:\V+)?\R){9}\V+$)","$1")
or
RESULTAT .= (RESULTAT?"`n":"") FIND6
ozzii
Posts: 343
Joined: 30 Oct 2013, 06:04

Re: Latest 10 lines of a variable

13 Oct 2014, 09:24

Thanks both of you.
I've gone with the regex because, I don't know why, I didn't success to do an array ;(
garry
Posts: 2285
Joined: 22 Dec 2013, 12:50

Re: Latest 10 lines of a variable

13 Oct 2014, 13:39

lack of knowledge from regex ...

Code: Select all

;- example LAST X-Lines --
;- test-file -------------
f1=%a_scriptdir%\test43.txt
ifnotexist,%f1%
{
e4x=
(Join`r`n
Line1
Line2
Line3
Line4
Line5
Line6
Line7
Line8
Line9
Line10
)
fileappend,%e4x%,%f1%
}
e4x=
;- END test-file ---------

x:=5    ;- example shows the last X lines

FileRead,aa, %f1%
StringReplace,aa,aa,`n,`n,useerrorlevel
aa=
N:=(Errorlevel+1)-X
loop,%x%
  {
  n++
  filereadline,ee,%f1%,%n%
  e .= ee "`r`n"
  }
msgbox,%e%
e=
ee=
return
;====================================
Guest

Re: Latest 10 lines of a variable

13 Oct 2014, 14:04

Old skool trick by Tuncay - last three lines using R option

Code: Select all

e4x=
(Join`r`n
Line1
Line2
Line3
Line4
Line5
Line6
Line7
Line8
Line9
Line10
)
StringGetPos, Pos, e4x, `n, R3 ; http://www.autohotkey.com/forum/viewtopic.php?p=262375#262375
StringTrimLeft, e4x, e4x, % ++Pos 
MsgBox % e4x
Can of course also be done with SubStr + InStr
garry
Posts: 2285
Joined: 22 Dec 2013, 12:50

Re: Latest 10 lines of a variable

13 Oct 2014, 14:11

thank you very much , Guest , a shorter / easier example

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], JackMa and 280 guests