[Tutor] Trying to extract the last line of a text file

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Oct 19 23:12:13 CEST 2006

> first count the number of lines in the file by using a loop. Use a 
> second loop and when teh counter reaches the num_of_lines values: take 
> the line.
> Is there any other way to do it??

Yes, there's a way to do it in one pass: you can keep track of the very 
last line you've read from the file at any given time.  As soon as you hit 
the end of the file, the auxiliary "last seen line" must be the last line.

More information about the Tutor mailing list