procmail
[Top] [All Lists]

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

2007-03-03 22:22:53
Michael,

sed?

That would need a temporary file -- that is, one I'd have to name and
clean up myself -- and the actual edits in question can be done with 
grep, so if the answer is to do my own handling of the inevitable 
temporary file, I'd probably use grep instead of sed.

perl -i?

I'll get to that in a reply to Don's answer.

What exactly do you mean by "edit"?

Remove obsolete single-line entries from files that other procmail
recipes append to.  One advantage of doing it within procmail is
compatible locking with those other recipes.

Don,

I know you're not a big fan of Perl but, unless the particular edits 
are such that this would be difficult to script or manage, it's a 
clean solution.

It's not a matter of fandom but of capability.  In my early days all
the perl documentation I saw was written under the assumption that the
user already knew C, so it lost me.

The '-i' option tells Perl to edit the file in place.
It takes an optional argument which becomes an extension to use for a
backup file. I don't know if a temporary file is used, but, if one 
is, it is cleaned up automatically.

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.)

Thank you both.

____________________________________________________________
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