Chuq von Rospach asked,
| I'm trying to write a recipe that'll search across multiple lines of a
| body, grab the found piece, and store it to a file as a single line
| with the newlines removed (or replaced)
|
| I can do this for a single line:
|
| ----
| :0 bfW:parsed.errors
| |egrep "^.*string I want"
|egrep "string I want"
will do the job just as well, but let's continue:
| :0 a:
| | formail -I "" >> procmail.parsed
Another digression: unless you need to preserve the blank line that separated
the head from the body, you can do that part far more efficiently this way:
:0ab:
procmail.parsed
Procmail will leave a trailing blank line at the end, so the entries in
$MAILDIR/procmail.parsed will still be separated. Anyhow,
| What I can't do is extend this to a second line:
|
| Original string:
|
| This is my key string:
| this is the data I want.
|
| So, how can I look for "key string", and stuff both lines into a file
| on one line? Unfortunately, changing the format of the incoming mail
| isn't possible.
Are you using a recent enough version of procmail (3.06 or later, I think)
to include extraction?
:0Bbfwi
* ()\/key string.*$.*
| echo $MATCH # or echo "$MATCH" if Chuq had wanted to preserve the newline
:0ab:
procmail.parsed
If "string I want" is right-anchored, omit the first ".*".
That can also be written this way, which may (or may not) run less
efficiently because while it does require forking a shell, filtering recipes
[so someone found out] involve grandchild processes.
:0Bi:
* ()\/key string.*$.*
| ( echo $MATCH ; echo ) >> procmail.parsed
You don't even need to keep the key string if you can do without it, because
you can move the extraction operator after it:
* key string.*$\/.*