procmail
[Top] [All Lists]

Re: Recipe needed: how to combine output of multiple filters run on a message body

1997-01-30 15:03:23
Stan Janet asked,

| How can I prepend the
| output of an arbitrary command (executed with the message body as
| input) to the body of the message. For example, I would like to add
| the output of:
|       grep <pattern>
| and then some delimeter in front of the body. It could be done several
| ways:
|     * String the body in a temp file and processing that multiple times
|     * Using a language like perl or awk that could store the lines of
|       the body internally and perform the necessary multiple passes
|       over them
|     * Capturing the output of the arbitrary in a variable, then
|       filtering the message by echoing the variable and writing
|       the body.

Personally, I'd do the third, or maybe its counterpart: capture the output
in a variable and then filter the head by writing out the head and echoing
the variable after it.  It depends on whether the mail you'll process this
way is likely to come in with long or short bodies.

| But is there another way that would be a little more elegant?

I'd like to know that myself.  I do the same thing in some of my own recipes
as I described:

   :0b
   VARIABLE=|command

   :0hfw
   | cat - ; echo "$VARIABLE" ; echo "$delimiter"

When I'm positive the variable will not have embedded newlines, this
saves a shell call:

   :0b # as before
   VARIABLE=|command

   :0hfw
   | sed "$ a\\
$VARIABLE\\
$delimiter\\
\\
"

but I get the feeling that Stan will be running a command with potential
mutli-line output.

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