procmail
[Top] [All Lists]

Re: Counting messages

1996-10-05 17:00:33
Antonio Bemfica asked,

| I am writing a shell script to process a message folder and output only
| the last "X" number of messages. I can use the +skip switch of formail,
| but initially my script has to find out how many messages are there in the
| folder ...

| This will output numbers sequentially, everytime formail splits a message:
| 
| #! /bin/csh -f
| 
| formail -s csh -c 'cat > /dev/null; echo $FILENO' < $1
| 
| Is there a way to get formail to give me only the final number in the
| series?  I realize this may be just a matter of shell programming, not a
| formail question, but it may also be much more obvious than I think, and I
| could use the help!

You really don't need to run both csh again and cat again for every letter in
the folder.  (In fact, cat does nothing for you up there, and 

  formail -s csh -c 'echo $FILENO' < $1

would have done the job, but it still would have forked a csh for every
letter in the folder.)  The list has discussed this before, and a few of us
had input on the results of that thread, but credit for the part that answers
Antonio's question belongs principally to Stephen van den Berg:

  formail -I'From x' -x'From ' -s < $1 | wc -l

(You could pipe to wc -w instead if you prefer.)  One formail and one wc,
that's all you need.

<Prev in Thread] Current Thread [Next in Thread>