how to read the last line of a huge file???

Emile van Sebille emile at fenx.com
Wed Jan 26 16:11:41 EST 2011


On 1/26/2011 2:59 AM Xavier Heruacles said...
> I have do some log processing which is usually huge. The length of each line
> is variable. How can I get the last line?? Don't tell me to use readlines or
> something like linecache...
>
>
seek

-rw-rw----    1 autofax  mail     1061716366 Jan 26 12:45 autofax
[root at wsgfw3 root]# python2
Python 2.3.5 (#1, Aug  3 2005, 08:40:39)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> f = open('/var/spool/mail/autofax')
 >>> f.seek(1061710000)
 >>> lines = f.read()
 >>> len(lines)
6366
 >>>

flavor to taste.

Emile




More information about the Python-list mailing list