Signed, this would be a nice feature, one that I wanted for a long time. In the meantime, if you're interested in a scripted workaround, here it is:
alias endread {
if (!$isid) return
if $0 > 2 {
if w isin $2 || r isin $2 { var %m = $v1, %l = 1, %s = $iif($4 isnum 2-,$4,1) }
else return
}
elseif $2 isnum 1- { var %m = l, %l = $2 }
else return
.fopen e $qt($1)
if ($ferr) return
var %p = $file($1) - 920, %i = 0
while %p > -920 {
if %p > 0 {
.fseek e %p
.fseek -n e
}
else .fseek e 0
var %d = $calc(920 - $fopen(e).pos + %p), %p = $fopen(e).pos
noop $fread(e,%d,&a)
var %t = $bvar(&a,1-).text, %n = $regex(%t,/\r?\n/g) + 1
if !%i && * $+ $crlf iswm %t {
%t = $left(%t,-2)
dec %n
}
if %m == l {
if %l <= %n {
.fclose e $regex(e,%t,/(?<=^|\n)(.*?)(?=$|\r?\n)/g)
return $regml(e,$calc(%n - %l + 1))
}
}
elseif %s <= $calc(%i + %n) {
var %t = $replace(%t,$crlf,$lf), $&
%j = $regex(e,%t,/(?<=^|\n)(.*?)(?=$|\r?\n)/g)
if (%m == w) var %c = $!wildtok($regml(e,%j),$3,0,0)
else var %c = $!regex($regml(e,%j),$3)
while %j {
if $calc(%i + %n - %j + 1) >= %s && $(%c,2) {
.fclose e
return $regml(e,%j)
}
dec %j
}
}
dec %p 920
inc %i $calc(%n - 1)
}
.fclose e
}
Its usage is exactly like $read(), except that not all switches are supported. More specifically,
w, r are supported
s, p aren't supported at all
n, t are implied
Valid examples are:
$endread(file.txt,1) = last line in the file
$endread(file.txt,w,*blah*) = first line from the end that matches *blah*
$endread(versions.txt,r,/mode(first|last)/,10) = line that matches "modefirst" or "modelast", but the file is searched from the 10th line from the end and upwards.
Oh and don't try to use it with files that contain lines longer than 900 characters, it will break most probably.
Note that even though I've tested this quite a lot, it may still have bugs. If you decide to use it, please do report back any bugs you find.
EDIT: Fixed a typo in the 5th line from the endEDIT 2: Removed that line, as it's completely unnecessary... probably a leftover from early triesEDIT 3: Yet another mistake corrected... hopefully the lastEDIT 4: Wishful thinking The alias is problematic, I'm looking into it but I may miss the 2-hour-edit-time window and have to repost