BB Unix Network Monitor - Message
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: {bb} {BB} OT: sed problem..
On Thu, 2006-01-19 at 15:56, Frank Timmers wrote:
> Hi brothers,
>
> With all the script guru's here I thought maybe one of you might be able
> to help out with a weird problem. I'm trying to escape the slashes in a
> date so I can use it in another search and replace. however it dos work
> from a normal command prompt, but not in a subshell:
>
> noob$ echo $session
> 2006/23/12
> noob$ echo $session | sed -e 's/\//\\\//g'
> 2006\/23\/12
> noob$ session_reg=`echo $session | sed -e 's/\//\\\//g'`
> sed: Function s/\//\\//g cannot be parsed.
>
> in the end I like to use ${session_reg} in the following line:
> cat backup.log | sed -e "s/${session_reg}/<A
> href=\"${session_html}.html\">${session_reg}<\/a>/" > backup.html
>
>
> the ${session_html} is created with the following ilne (and works..):
> session_html=`echo $session | sed -e 's/\//_/g'`
This kind of thing can get pretty nasty. If you're doing a lot
of substitutions, it's normally easiest to replace the character
that needs escaping with one that does not (or multiples thereof)
and swap back before output. Just make sure that the replacement
you use will not occur in the input files.
That said, for cases where you need to keep the escapes, you must
double them whenever the shell parses them (including sub-shells).
as a result, the following works (for me at least).
session_reg=`echo $session | sed -e 's/\\//\\\\\\//g'`
Cheers, Phil.
--
Dawn, n. The time when men of reason go to bed. (Ambrose Bierce)
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=
To unsubscribe from this list, or to subscribe to the bb-digest list
send e-mail to mailto:majordomo@bb4.com with unsubscribe bb -and/or-
subscribe bb-digest in the BODY of the message.
Home |
Main Index |
Thread Index