[Tutor] Matching problem....
Michael P. Reilly
arcege@shore.net
Thu, 7 Oct 1999 20:25:43 -0400 (EDT)
> I'm working on a silly project -- an APOP server -- <cough> and I'm having
> a problem coming up with an equivalent to the following command line. I'd
> rather not just have this as a commands.getstatusoutput() (which I could
> do and is in fact what I'm doing now...)
>
> cat /var/spool/mail/deirdre | grep ^From\ | wc
>
> or, for you egrep fans:
>
> egrep '^From\ ' /var/spool/mail/deirdre | wc
>
> What I want is ONLY the count of the matches. I don't, at this point, care
> a hoot about the matches themselves. That comes later. :)
>
> I'm *also* interested in the following:
>
> egrep '^From\ ' /var/spool/mail/deirdre -b
>
> ...but at a different point in time. :)
Starting with:
>>> import string
>>> mbox = open(mboxfname).read()
How about:
>>> howmanymsgs = len(string.split(mbox, '\nFile '))
This runs in under a second for 80 msgs totaling about 1.5 Mbytes.
And from the grep side, you could run. ;)
grep -c '^From ' /var/spool/mail/deirdre
Good luck.
-Arcege
--
------------------------------------------------------------------------
| Michael P. Reilly, Release Engineer | Email: arcege@shore.net |
| Salem, Mass. USA 01970 | |
------------------------------------------------------------------------