procmail
[Top] [All Lists]

Figuring out which rc file to read (was Re: Thanks!)

1997-08-13 23:17:00
On Thu, 14 Aug 1997 08:04:58 +0300 (EET DST), I wrote:

[speaking of making a complete ass of oneself ... :-]

    :0B
    RCFILE=`tr -c "-A-Za-z'" '\012' | sort | join -o 2.2 - mapping.file`

Just for the record, perhaps I should explain how stupid this is. For
one thing, I was still thinking about matching only in the body.
Secondly, this assumes you have single magical "keywords" you want to
match against. 
  The tr will simply chop the whole message into one word per line
(only I didn't test it; it should be tr -c "'A-Za-z-" instead) and
then the rest should be fairly obvious (except join is not always very
obvious -- it's one awkward program to use. Note that the mapping.file
also needs to be sorted). And it will of course return all the
matches, and not in the order they matched, but in alphabetical order.
Nice if the first string in the sorted mapping should override all
others, not so very nice otherwise :-)
  Finally, the B flag is not right. (I had a different construct at
first where it would have been right, but then decided to change ...)
  So here's something that might work better:

RCFILE=

:0hi  # Header words to match
RCFILE=| gawk '/word1|word2/ { print "rcfile.one" ; exit }
               /word3|word4/ { print "rc.two"     ; exit }'

:0bi # Else match in body
* ! RCFILE ?? .
RCFILE=| gawk '/str1|string two/  { print "rc.three" ; exit }
              /long phrase three/ { print "rc.4four" ; exit }'

:0   # If there is an RCFILE for some reason, source it
* RCFILE ?? .
{ INCLUDERC="$RCFILE" }

The awk is not very polished, but it does more sensible things than
the join thing, at least.

Perhaps you should take this, too, with a grain of salt ...
  Still, hope this helps,

/* era */

Seems the :E flag doesn't look at awk's exit code here?

-- 
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>
  • Re: Thanks!, era eriksson
    • Figuring out which rc file to read (was Re: Thanks!), era eriksson <=