procmail
[Top] [All Lists]

Re: best way to edit a file from a procmail recipe

2007-03-03 22:56:57
On  3 Mar, David W. Tamkin wrote:
[...]
The '-i' option tells Perl to edit the file in place.
[...]
I'd never heard of the option, but it doesn't surprise me that perl 
includes it.

If I can run any tests for you, I'd be happy to do so.

Well, every day it has to remove the entries from the second day before,
which can be identified by the day of the week.  That perhaps can be set
in a command line parameter figured out within procmail, but I'd suppose
that perl can determine it internally as well.

One stumbling block: I don't have shell access there and it would be a
problem to find out whether perl is even installed.  Sed and grep
definitely are.  (To be honest, I don't even know about ex, but I'd
assume that ed is present.)

You can test the existence easily enough.

   :0 fbw
   * ^Subject: Do I Have Perl\?
   |perl -v                       # -V for more verbose

   :0A:
   $DEFAULT

It sounds like the perl one-liner should be simple enough. The '-p'
option tells Perl to automatically print each output line without an
explicit print statement. This makes it work something like sed.
Perl has access to the environment (I use $ENV{MATCH} for procmail's
$MATCH in numerous places), so something like this would do the trick:

   DELETE=Monday

   :0 hi
   |perl -i -pe 'next if /^$ENV{DELETE}/;' path/to/your/file

That, of course, assumes the day of the week is at the beginning of the
line.

Don Hammond


-- 
Email address in From: header is valid  * but only for a couple of days *
This is my reluctant response to spammers' unrelenting address harvesting


____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail