Hello, I have a complicated seen script, and I just have a problem, so I'm only showing edited parts of it for easy understanding.

Code:
on *:text:*:*: { 
    write -w" [ $nick ] $+ :*" seen.txt $nick $+ : $+ [ $ctime ] $+ : $+ [ $chan ] $+ :saying " $+ [ $1- ] $+ "
}


Code:
alias seen {
  var %temp, %chan, %nick
  %nick = $1
  %chan = $2
  %seennick = $3
  %temp = $read(seen.txt,w,%seennick $+ :* )
  if (%temp) {
    tokenize 58 %temp
    if ($1 == %nick) { 
      /msg %chan %nick $+ : there you are!
    }
    else { 
    /msg %chan %nick $+ : I last saw $+ $1 $+ in $+ $3 $+ $duration($calc($ctime - $2)) ago, $4- }
  }
  else { 
    /msg %chan %nick $+ : I've never seen $+ %seennick $+ in $+ $2 $+ before. }
  }
}


So let's say I someone says 'word 1' then the seen would return, 'word 1' Then let's say someone says 'word 2' etc.

But how do I get it to return the second or third last line?

In seen.txt, it will look like:


Neal:1124335052:#channel1:saying "word 2"
Neal:1119168890:#channel1:saying "word 1"

Notice the ctime, it is not in chronological order.

So the problem with this is:

%temp = $read(seen.txt,w,%seennick $+ :* )

I have tried

%temp = $read(seen.txt,w,%seennick $+ :*, $calc($readn +1) )

And

%temp = $read(seen.txt,w,%seennick $+ :*, $calc($readn -1) )

So, how would I return the second last line, and, how do I /write this in chronological order?

Thanks.