PSE-L(_at_)mail(_dot_)professional(_dot_)org (Professional Software
Engineering) writes:
At 16:32 2001-06-08 -0400, Evans, Tim wrote:
I want to extract the hostname from the subject line and save the message in
a folder named for the host:
Whem you want to extract part of something, you should consider checking
out the $MATCH construct. See the manpages.
:0:
* (^SUBJECT:.*)myspecificstringofcharacters.*
HOST=`/usr/bin/echo \"${SUBJ}\" | /usr/bin/awk '{print $NF}'`
$HOST
Why not use $MATCH? You toss the need to execute formail, a shell, echo,
and awk:
:0:
* ^Subject:.*myspecificstringofcharacters /\.*
$MATCH
Close, but not quite. He wanted the last field, not just everything after
"myspecificstringofcharacters". That makes the conditions slightly more
complicated:
# First, extract the last set of non-whitespace characters before
# the newline that ends the header field, plus that newline.
# Then, trim that newline from the extracted result.
:0:
* ^Subject:.*myspecificstringofcharacters.*[ ]\/[^ ]+$
* MATCH ?? ^^\/.+
$MATCH
If you remove the '$' then it'll extract the first set of non-whitespace
characters after "myspec...", because procmail's regexps are not 'greedy'
on the lefthand side of the \/ token, such that the ".*[ ]" will
match as little as possible while still letting the entire condition
match. The '$' forces the condition to match the entire header field,
so the ".*[ ]" has to match everything in the middle.
The "[ ]" right before the \/ token is actually unnecessary--the ".*"
is sufficient given what's after the \/ token--but it makes the intent
clearer (and it should be ever so slightly faster, I think).
Of course, if he guarantee that there will only be one field after the
"myspeci..." string, then your version is simpler, clearer, and faster.
Philip Guenther
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail