procmail
[Top] [All Lists]

Re: Trimming the end of a string

2009-11-22 22:05:10
At 19:38 2009-11-22 -0700, LuKreme wrote:
I have a variable, let's call it MYVAR and I want to cut the string "-bar" from the end if it's there.

I can match/preserve strings at the end of variables, but I don't remember how to cut them when I don't know what the first part of the variable might look like.

I don't want to resort to sed unless I have to, but I thought there was a procmail way to do this.

You're probably vaguely picturing the method I use to split an email address to address vs. domain portion - possible because the @ in the middle is known to not be a valid character within either half.

From my published sandbox:

        # get the From: address as an address component ONLY (no comments)
        :0 h
        CLEANFROM=|formail -IReply-To: -rtzxTo:

        # username portion
        :0
        * CLEANFROM ?? ^\/[^(_at_)]+
        {
                FROM_USER=$MATCH
        }

        # domain portion
        :0
        * CLEANFROM ?? @\/.*
        {
                FROM_DOMAIN=$MATCH
        }


--

Alternatley, you may be thinking of the recipe within listname_id.rc, which strips "-owner" from a listname. From that rcfile:

# The second and third conditions were found in posts from Bart Schaefer
# dated 2002-07-18 - these optimize this fallback recipe so that it
# doesn't require the use of a shell, pipe, and sed to eliminate the -owner
# suffix.
#
# first, get the owner address (if the sender follows that syntax)
# Grab everything up through the last hyphen
# Grab everything except that last hyphen
# This is optimized to be one recipe, since MATCH will assume the set value
# after each condition line, and if the FIRST condition matches, the two that
# follow it definatley should.
:0E
* ^Sender:[     ]*\/[-A-Z0-9_+]+-owner
* MATCH ?? ^^\/.+-
* MATCH ?? ^^\/([^-]|-[^-])+
{
        LISTNAME=$MATCH
}



--

I suspect that latter recipe there may prove more appropriate to what you're attempting than the first.

---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

____________________________________________________________
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

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