Monkey With A Gun
2003-08-07 01:54:33 UTC
I'm trying to read a file line-by-line but in reverse order (ie, last line
first), and have some success using...
set fid [open "|tail -r $file" r]
while {![eof $fid]} {
puts [gets $fid]
}
Unfortunately, "tail -r" isn't very portable, so I was wondering if anyone
could give me pointers on how to accomplish the same in pure Tcl?
The only other solution that's struck me is to use a combination of seek,
tell and read to inch my way backwards through the file one char at a time
looking for newlines, but that seems very inefficient,
TIA.
first), and have some success using...
set fid [open "|tail -r $file" r]
while {![eof $fid]} {
puts [gets $fid]
}
Unfortunately, "tail -r" isn't very portable, so I was wondering if anyone
could give me pointers on how to accomplish the same in pure Tcl?
The only other solution that's struck me is to use a combination of seek,
tell and read to inch my way backwards through the file one char at a time
looking for newlines, but that seems very inefficient,
TIA.