procmail
[Top] [All Lists]

Re: matching when two lines match

2001-03-31 21:51:15
Timothy asked,

| I have this and it works well:
| 
| 
|       :0B
|       * $ ^Wrote file \/.*
|       { ATTACHMENT=$MATCH }

You don't need the "$" modifier there.

| But if there is more than one occurence of ^Wrote file in the email, it
| still only matches 1 :-(
| 
| How can I $MATCH all of the occurences, especially when I have no idea how
| many there might be ?

What exactly do you mean?  You can't extract scattered selections from the
message into $MATCH.  I'm guessing that you want the rest of every line that
begins "Wrote file " (and doesn't end there) in the variable, and that's not
going to happen within procmail.

To extract the *last* occurrence,

  :0B
  * 1^1 ^Wrote file \/.*
  { ATTACHMENT=$MATCH }

but to get all of them (and let's hope that you'll settle for having them
separated from one another with newlines and a trailing newline in the value
of the variable, procmail needs outside help, such as sed:

  :0Bb
  * ^Wrote file ()
  ATTACHMENT=| sed -n 's/^Wrote file //p'

Except for one thing: I'd imagine that a line consisting of "Wrote file " and
ending at the second space is of no use to you and you don't really want to
extract the null string from it; so let's change those recipes to use only
lines that have something after the second space:

  :0B # to extract first occurrence
  * ^Wrote file \/.+
  { ATTACHMENT=$MATCH }

  :0B # to extract last occurrence
  * 1^1 ^Wrote file \/.+
  { ATTACHMENT=$MATCH }

  :0Bb # to get all occurrences -- note trailing space+period
  * ^Wrote file .
  ATTACHMENT=| sed -n 's/^Wrote file \(.\)/\1/p'

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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