Finding messages in huge mboxes

Miki Tebeka miki.tebeka at zoran.com
Tue Feb 3 02:31:14 EST 2004


Hell Bastiaan, 

> I need find messages in huge mbox files (50MB or more).
> ...
> Anyone who has a better idea?
I find that sometime using the unix little utilties (which are
available for M$ as well) gives very good performance.

--- last.py ---
#!/usr/bin/env python
from os import popen
from sys import argv

# Find last "From:" line
last = popen("grep -n 'From:' %s | tail -1" % argv[1]).read()
last = int(last.split(":")[0])
# Find total number of lines
size = popen("wc -l %s" % argv[1]).read()
size = int(size.split()[0].strip())
# Print the message
print popen("tail -%d %s" % (size - last, argv[1])).read()
--- last.py ---
Tool less than 1sec on my computer on a 11MB mailbox.

HTH.
Miki



More information about the Python-list mailing list