[scilab-Users] mgetl question

Allan CORNET allan.cornet at scilab.org
Mon Apr 11 08:27:24 CEST 2011


Hi,

It depends if your files are big or not, two ways to do:

Example:

D:\lastfourlines.txt
line .
line ..
line ...
line ....
line .....
line ......
line n - 4
line n - 3
line n - 2
line n - 1
line n

1]
txt = mgetl("d:\lastfourlines.txt");
lastfourlines = txt($ - 3:$)

2]
lastfourlines = [];
fd = mopen("d:\lastfourlines.txt", "rt");
while (meof(fd) == 0)
  txt = mgetl(fd, 1);
  lastfourlines = [lastfourlines;txt];
  if size(lastfourlines, "*") > 4 then
    lastfourlines = lastfourlines($ - 3:$);
  end 
end
mclose(fd);
lastfourlines

in 1] file is fully loaded in scilab then in 2] you load only line by line

Best regards

Allan

-----Message d'origine-----
De : computidoo [mailto:ychattah at iai.co.il] 
Envoyé : dimanche 10 avril 2011 10:43
À : users at lists.scilab.org
Objet : [scilab-Users] mgetl question

Hello
I have atext file and i want to read the last 4 lines in the file .
I was using mseek with the end of the file but i have problems as the
function is for binary files.
i there any other posibility?
best regrad
computidoo

--
View this message in context:
http://mailinglists.scilab.org/mgetl-question-tp2801892p2801892.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at
Nabble.com.




More information about the users mailing list