procmail
[Top] [All Lists]

Re: search for keyword/delete paragraphs

1999-06-17 19:07:04
Tom Adler asked,

| First, I would like to forward a copy of e-mails that contain a certain
| keyword within the message body to an alphanumeric pager.  I subscribe to a
| weather warning notification service and wish to forward only messages that
| contain, within the body, the name of my county.

No problem at all.  Use the capital-B flag on the recipe, or if it has other
conditions that must search the head or the entirety, use the B ?? modifier
on the condition that searches for the county name.

| Second, after identifying such a message, I want to delete from the forwarded
| copy any paragraphs that do not begin with an asterisk.  These paragraphs are
| the ones containing the pertinent info, and since my pager is limited to
| about 200 characters I need to remove the extraneous stuff.

A lot depends on the specifics; are the paragarphs separated by blank lines?
Is the asterisk at the start of a pargraph flush against the left margin or is
it indented?  Are there other asterisks in the text?

If the asterisks are flush left and there is an empty line between each two
paragraphs,

 :0bfw
 | sed '/^\*/,/^$/!d' # or, sed -n '/^\*/,/^$/p'

| An alternate tactic would be to delete everything in the (forwarded) message
| body prior to encountering the first asterisk.  Would this perhaps be
| simpler to code?

 :0bfw
 | sed '/\*/,$ !d' # or, sed -n '/\*/,$ p'

[When we have some more details from Tom, then we'll get into the matter of
 temporarily unsetting SHELLMETAS.]

Actually, that keeps the whole line that contains the first asterisk and then
everything below it.  We could code to delete characters on the line of the
topmost asterisk that are to the left of it, but that seems unnecessary if
the paragraph begins with an asterisk.