Hi all,
I've got a problem with sed. Want to use it to add escape character \ before $ and ' symbols so
condition='1'$some
will become condition=\'1\'\$some
echo "condition='1'$some" | sed 's/\($\)/\\\1/g'
is not working properly. Can somebody help me with this please?
Regards, Johny
zaxxon
March 2, 2011, 4:16am
2
$> cat infile
condition='1'$some
$> sed "s/['\$]/\\\&/g" infile
condition=\'1\'\$some
Thanks, much better but one problem: it cuts the end of string:
echo "cond='1'$some" | sed "s/['\$]/\\\&/g"
result
cond=\'1\'
Thanks, much better but one problem: it cuts the end of string:
echo "cond='1'$some" | sed "s/['\$]/\\\&/g"
result
cond=\'1\'
Its because the variable $some gets expanded. Escape the $ in the echo statement and try.
aigles
March 2, 2011, 4:51am
5
I think that the problem comes from the echo statement.
The string to display is between ", the shell expands the variable $some which may be not defined.
What is the argument you pass to the script above..?
not actual. Remove the post