procmail
[Top] [All Lists]

Re: Problem with lists expansion

1997-04-29 06:20:00
Talking to myself as usual: 

On Tue, 29 Apr 1997 14:21:13 +0300 (EET DST), I wrote:
On Tue, 29 Apr 1997 12:46:35 +0200 (MET DST),
"Pascal A. Dupuis" <dupuis(_at_)lei(_dot_)ucl(_dot_)ac(_dot_)be> wrote:
- a variable is initialised as 
CPDOM1=`cat $HOME/filters/cpdomains.1 | tr '\012' '|'`

By the way, you have an Useless Use of Cat award here. 
tr '\012' '|' < $HOME/filters/cpdomains.1 saves one process
[and shows how you have been doing your homework :-]. 

    sed -e 'y/\n/|/' -e 's/\|$//' 

I was unable to get any variant of this to work on two of the Unices I
tried it on (Digital/OSF1, Sun) although they choked mainly on the
newline in the y//. You are in a twisty maze of sed implementations,
all different, so your mileage may vary. The following worked on
Linux:

    sed -e 'y/
/|/' -e '$s/|$//'

Given the problems with sed in general, I'd be partial towards using
Perl instead;

    perl -pe 'y/\n/|/; s/\|$// if eof'

Scripts with hard newlines in them are not practical in Procmail; I
may be showing my ignorance here, but if I really need something like
this, I usually end up doing something like

    SEDSCRIPT="sed -e 'y/
/|/' -e '$s/|$//'"

    :0
    * Conditions ...
    | $SEDSCRIPT

Tangentially, you would of course be saving a last itsy bit of
resources by doing the "heavy" processing once and for all, i.e.
perhaps transforming the Cyberpromo file into a procmail rc file
directly, and using that: 

    #!/bin/sh
    echo ':0'
    echo '* Subject: (\'
    sed -e 'y/
/|/' -e '$s/|$/)/'
    echo '$TRASH'

Assuming you saved this file in $HOME/filters/script, you could do the
following every time you get an updated version of the Cyberpromo
domain file: 

    cd $HOME/filters
    ./script <cpdomains.1 >cpdomains.rc

(or do it automatically from within a Makefile or cron job or
whatever), and just use the resultant file from within your
.procmailrc file: 

    INCLUDERC=$HOME/filters/cpdomains.rc

Oh well, I'll shut up now. 

/* era */

-- 
Defin-i-t-e-ly. Sep-a-r-a-te. Gram-m-a-r.  <http://www.iki.fi/~era/>
 * Enjoy receiving spam? Register at <http://www.iki.fi/~era/spam.html>

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