|
|
Re: Number of line in a text file
Posted:
Nov 2, 2006 10:51 AM
|
|
Benoît Valley wrote: > And what are the commands to break the file in parts before reading > it ? > > Thanks for your useful suggestion and help. > Benoît > > Kirill wrote: > > > > > > You will need to read it anyway so the only resort is to reduce > > function call overhead: reading it by bug chunks, 10th or 100ths > > megabytes, will be much faster. > > Kirill > > > > Benoît Valley wrote: > >> I need to determine the number of line in a text file. > >> > >> Is there a more efficient way that using getl in a while loop ? > >> > >> Thanks, > >> Benoît > > > >
No need to break it up. If the file fits in memory, the following will render you the number of lines:
fd=fopen('foo.txt'); q=fread(fd,inf,'*uchar'); fclose(fd); nlines=sum(q==10);
This works on a PC or UNIX textfile. Guess you have to replace '10' for '13' on a MAC.
If the file is huge, modify it to read in chunks.
/jewa
|
|