procmail
[Top] [All Lists]

Re: search for keyword/delete paragraphs

1999-06-17 21:11:28
On Thu, 17 Jun 1999 22:28:23 -0500, Tom Adler <adlertom(_at_)execpc(_dot_)com>
wrote:
So, would my completely modified recipe look like this?
:0c
*^From:(_dot_)*weather(_at_)service(_dot_)com
:0B
*county
:0bfw
 | sed '/\*/,$ !d'
!mypager(_at_)pagercompany(_dot_)net

No, you have to have an action (or brace) for each :0something line,
and one :0something line for every action (or brace). (See separate
posting about this recently.)

    :0c
    * ^From:(_dot_)*weather(_at_)service\(_dot_)com
    * B ?? county
    {
        :0fbw
        | sed '/^\*/,$!d'

        :0
        ! mypager(_at_)pagercompany(_dot_)net
    }

The B ?? is more convenient than another set of braces IMHO but you
can certainly write it like

    :0
    * ^From(_dot_)*weather(_at_)service\(_dot_)com
    {
        :0Bc  # yes, the "c" should only happen at this point
        * county
        {
            :0fbw
            | sed '/^\*/,$!d'

            :0
            ! mypager(_at_)pagercompany(_dot_)net
        }
    }

I posted a sed script in private which would do the filtering and
sending in one fell swoop, but David's approach is more efficient, on
a couple of counts. For completeness' sake, here's (something like)
what I proposed:

    :0cw
    * ^From(_dot_)*weather(_at_)service\(_dot_)com
    * B ?? county
    | sed -e '1,/^$/b' -e '/^\*/,$!d' \
      | $SENDMAIL $SENDMAILFLAGS mypager(_at_)pagercompany(_dot_)net

This looks a lot more concise, but that means it's also harder to
adapt to new situations. It's less efficient than David's script
because the headers are needlessly being pushed through sed, and
there's the overhead of an extra shell because of the pipeline.
(Or is there a shell with David's sed script, too? He promised he'd
get back on this.)

Hope this helps,

/* era */

-- 
.obBotBait: It shouldn't even matter whether     <http://www.iki.fi/era/>
I am a resident of the state of Washington. <http://members.xoom.com/procmail/>
 * Sign the European spam petition! <http://www.politik-digital.de/spam/en/> *