Special character \

Hi,
In the shell script, i need to remove the special charater "\" with "\\". For example, i need to replace "D:\FXT\ABC.TXT" with "D:\\FXT\\ABC.TXT".

However, when trying to do something like , i get the below error :-
-->echo "D:\FXT\ABC.TXT" | sed -e 's#\#\\#g'
sed: 0602-404 Function s#\#\\#g cannot be parsed.

Can you suggest me why this is wrong , or how to replace the above.

Thanks.

With this...

echo "D:\FXT\ABC.TXT" | sed 's/\\/\\\\/g'

you need to escape the '\" also since its a special character for sed.

echo "D:\FXT\ABC.TXT" | sed -e 's#\\#\\\\#g' 

should work.

Hi,
Thanks for your reply.
The above is working fine in standalone basis,
When I try to assign this to a variable, the same error comes :-
$1= echo
var1=`echo "D:\FXT\ABC.TXT" | sed 's/\\/\\\\/g'`
sed: 0602-404 Function s/\/\\/g cannot be parsed.

Any pointers ?

Perhaps you have an old version of sed....What's your OS ???

Its IBM AIX 5.1.
But any pointers ?

Sometimes quoting backslashes can be tricky and surprising. If quoting them once solved it the first time, I would try quoting them again to solve the same error the second time.

var1=`echo "D:\FXT\ABC.TXT" | sed 's/\\\\/\\\\\\\\/g'`

if you are using bash shell then try this:

a="D:\FXT\ABC.TXT"
echo ${a//'\\'/'\\'}