4/27 sed "s/$var1/$var2/" file
I need the double quotes so that it will use the the value
of the variables, var1 and var2, rather than search for the
string '$var1'. However, these variables, themselves,
contain special characters, and so sed isn't working right.
How can I quote the special characters within the variables?
\_ use perl
\_ Just for fun, how do you do it with sed?
\_ this has not so much to do with sed as it does your
shell, dude.
\_ Piping the variable through sed 's/\//\\\//g' will get
rid of '/' and similar expressions will get rid of other
special characters.
\- it will be very tough to do this realiably for tcsh,
because you need to handle $, space and history chars
slightly differently. there are really klugy approaches
but it is best not to use csh/tcsh here. for a specific
purpose, you can probably come up with something, but for
general input/hostile input, i dont think so. --psb
\_ ASSUMING only slashes are your problem, this gets you:
sed "s/`echo $var1 | sed 's/\//\\\//g'`/`echo $var2 | sed 's/\//\\\//g'`/" file
Yukola...
\_ in other words, use perl you dweeb.
\_ Well, you can get around the slash problem by using
a different character for the delimiter: s:$var:$var2:g.
But it's still a problem for perl. -tom
\_ shell programming sucks
\_ Mmm... sweeping, pointless statement.
\_ Trivial, obvious statement, just like this one.
\_ If I set the BOZO flag to off, will *nix automagically
migrate all sweeping, pointless, trivial, obvious
statements to specific, meaningful, vital, esoteric
statements? |