procmail
[Top] [All Lists]

Re: delete matching line from file

2001-03-11 10:58:01
Aaron provided Tom a lot of pointers and came up with this recommendation:

| So, the complete recipe would look something like:
| 
| :0
| * ^Subject: Re:[  ]+\/[^      ].*
| {
|   STRINGTOCHECK = $MATCH

Actually, there's no need to save the value in a different variable, so
there's no need to open the braces either.

|   :0cwi: $HOME/mail_log.$LOCKEXT

Given that $LOCKEXT already starts with a period, we don't need two.  As long
as you consistently use .$LOCKEXT all the time, it will work, but if there is
some other recipe where you let procmail infer the name of a local lockfile
from $HOME/mail_log, it will have only one period, not two, so there could be
clashes.

|   | sed -e "/$STRINGTOCHECK/d" $HOME/mail_log > $HOME/mail_log.tmp && \
|     mv $HOME/mail_log.tmp $HOME/mail_log

Hmm.  I should think that grep -v would be more efficient than sed there.
However, I'd go another way myself, just to avoid the temporary file.

 :0cwi: $HOME/mail_log$LOCKEXT
 * ^Subject: Re:[  ]+\/[^       ].*
 | (echo "/$MATCH/d" ; echo wq) | ed -s $HOME/mail_log

That's still imperfect, because a slash in the subject can mess it up (and
Aaron's suggested code has the same problem; Tom's would have as well if it
would have expanded the variable at all).  But I have to run now, so let's
get back to that later.

_______________________________________________
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>