procmail
[Top] [All Lists]

RE: catching backslashes with sed

2002-09-16 11:39:33
Greg Matheson <cid88201(_at_)mail(_dot_)chinmin(_dot_)edu(_dot_)tw> wrote:

I seem to have it working with s/\\\\//g

Very good.


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.

Yes.

        {
           # 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.

As someone answered the other day already, it's actually a
standard sed syntax.  The -e '[expression]' -e '[expression]'
thing is not the only way.  Most any modern sed can do it
the way I showed it, too.  Very ancient seds would not be
able to, however.


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/thre
ads.html#00139

shows the discussion by Dallman Ross and Volker Kuhlmann
developed from problems with a vacation autoresponder.

Glad you found it!

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.

I'm not entirely clear on what you're asking.  But it sounds like
you got what you wanted working, so -- great!

Dallman

-- 
Dallman Ross

"If you find a path with no obstacles, it probably does not lead to
anywhere."
        Thoughts of Rev. Sunnan Kubose, from _Zen in the Markets_ 

_______________________________________________
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>