On 21 Apr, Trevor Jenkins wrote:
| I'm having little success using sed in assignments to environment
| variables.
|
| Doing something like this does work:
|
| SUBJECT=`formail -zxSubject: | sed "s/mail]/mail] /g"`
|
| but this doesn't:
|
| TAG=`echo -n $SUBJECT|sed -e "s/\[([A-Za-z0-9\-_ ]*)\]/\1/g"`
|
| I've tried the failing echo and sed combination in an interactive shell
| and it works. (That is it captures any alphanumerics between brackets.)
| However when I try the above procmailrc line it fails.
That this works at a shell prompt seems unlikely. Using the same version
of sed here (GNU v3.02) it doesn't do what you want, nor would I expect
it to. The first problem is the back reference requires escaped
parentheses. I believe you're trying to match literal parentheses inside
of brackets above. The second problem is, even after escaping the
parentheses, your just replacing "[tag]" with "tag" and not changing any
text before or after. You probably want something more like:
TAG=`echo $SUBJECT |sed 's/.*\[\([-A-Za-z0-9_ ]*\)].*/\1/'`
I would just note that this still might not do what you want if fed
multiple bracketed tags, or unmatched brackets. Presumably the procmail
code deals with those possibilities.
I would also suggest using the built-in match operator and skipping sed
altogether.
:0
* ^Subject:.*\[[-A-Za-z0-9_ ]+]
* ^Subject:.*\[\/[-A-Za-z0-9_ ]+
{
TAG=$MATCH
}
The first condition makes sure there is at least one pair of brackets,
the second condition extracts the contents within the _first_ bracket
pair for assignment to TAG within the braces.
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail