Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: Number of line in a text file
Posted:
Nov 10, 2006 4:56 AM


Ok. I have now a very efficient way to know the number of line in my text file. Is it now possible to read very quickly just the last line of the file ?
fgetl do not permit to acceed directly the last line of the file.
using dlmread with appropriate range is slow. Is there a quick way to get the content of the last line ?
Thanks for your helps.
Benoît
Benoît Valley wrote: > > > Thanks a lot for your explanations. > Benoît. > > Kirill wrote: >> >> >> Indeed  4.65sec vs former 7.6sec!!! >> >> JWagberg wrote: >>> Kirill wrote: >>> > while ~feof(fh) >>> > ch = fread(fh, chunksize, 'uchar'); >>> > if isempty(ch) >>> > break >>> > end >>> ... >>> > n2 = n2 + sum(ch == char(10)); >>> >>> >>> Prepend the 'uchar' with an asterisk, '*uchar', and you can > read >> eight >>> times as much with each chunk and the (ch == char(10)) will > also >> speed >>> up by a factor five. >>> >>> /jewa >> >>



