procmail
[Top] [All Lists]

Re: File Updating via Procmail

1997-08-20 13:34:27
Era Eriksson suggested to Jeff Halper,

| :0:
| * Subject:(.*\<)?XYZ\>
| | sed -e '1,/^#(_at_)#$/d' '/^#(_at_)#$/,$d' >/user/public_html/filefix.html

Triple youch.

First, procmail will kvetch that it cannot determine an implicit lockfile
name (there is a ">" in the action but it takes ">>" to imply a lockfile on
a pipe action).

Second, sed will barf on the inability to find a file named "/^#*#$/,"
[assuming that the variable $d is currently unset].  It would be a very
unusual system that had a directory named /^#*#$ regardless of what $d
might currently be.

Third, procmail will howl about a write error because sed didn't accept stdin
from procmail.

Let's fix those little nits and improve the sed script a little:

  :0:/user/public_html/filefix.html.lock
  * Subject:(.*\<)?XYZ\>
  | sed -ne '1,/^#(_at_)#$/d' -e '/^#(_at_)#$/q' -e p 
/user/public_html/filefix.html
# or | sed -ne '1,/^#(_at_)#$/d; /^#(_at_)#$/q; p' 
/user/public_html/filefix.html
# if your sed groks semicolons.

Again, as Era pointed out, this will eliminate everything from the *second*
"#(_at_)#" on; if there are more than two appearances of "#(_at_)#", it would 
be very
difficult to write sed instructions that could figure out which is the last
unless the entire text from the second "#(_at_)#" to the end could fit into 
sed's
hold space.

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