procmail
[Top] [All Lists]

Re: catching backslashes with sed

2002-09-14 16:32:55
I seem to have it working with s/\\\\//g

On Sat, 14 Sep 2002, dman(_at_)nomotek(_dot_)com wrote:

From: Greg Matheson <cid88201(_at_)mail(_dot_)chinmin(_dot_)edu(_dot_)tw>

I'm trying to construct a filename out of an email address, using
sed to x-out all the metacharacters, and seem to have mostly
succeeded with:

Except for the last sed expression to replace backslashes with 'x' :-(

Anyway, you need to quote backslashes multiple times.  But the
problem can also arise from "echo", which can barf on some
magic chars.

The results with GNU echo seem to be the same as with printf.

The following, from one of my rc files, works to handle the backslash
and a couple of other chars.  Adjust for your own needs:

        :0  # save us from possible SUBJ bombs when calling sed
        * SUBJ ?? [&\/]

This means do the substitution only if $SUBJ contains one of these
metacharacters.

        {
           # we're using printf %s to replace echo, which is not
           # consistent in its handling of escape quotes

           SUBJ = `printf %s "$SUBJ" | sed 's,\\\\,\\\\\\\\,g; \
                                            s/&/\\\\&/g;       \
                                            s,/,\\\\/,g'`

So you're trying to preserve the metacharacters by quoting them.
Strange sed syntax there with the colons and lack of -e for extra
expressions. I think 'sed' has been deleted from 2nd and 3rd
lines here.

This was posted to the list about two years ago as part of a
thread..

The thread index at
http://www.rosat.mpe-garching.mpg.de/mailing-lists/procmail/2000-04/threads.html#00139
shows the discussion by Dallman Ross and Volker Kuhlmann
developed from problems with a vacation autoresponder.

I didn't understand all the discussion, but I am probably going
to leave it because I have gotten rid of the backslash with
s/\\\\//g

But I still don't understand why y/\\\\// doesn't work.
I guess it's the difference between a regex and a literal
expression.

-- 
Greg Matheson            No trees were killed in the sending of this message. 
Chinmin College          However, a great many instructions were executed. 
                         --from Richard Rognlie's signature
Taiwan Penpals Archive <URL: http://netcity.hinet.net/kurage>
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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