Bash – How to remove escape char from string in bash using sed

bashcharacterescapingsedunix

I need to remove escape character from the string in bash. I get a data structure, which contains url paths with / escaped so I receive the regular link:

http://stackoverflow.com/questions/ask

as one with escaped /:

http:\/\/stackoverflow.com\/questions\/ask

Now I need to remove \ from the second link. For this purpose I tried using sed

 `echo '"'${paths[$index]}'"' | sed "s@\\@@g"`

But I get an error:

sed: -e expression #1, char 6: unterminated `s' command

If I replace \\ with ie. _ it works like a charm and removes all occurrences of _ in a string. How do I get rid of escape characters in a string using sed?

Best Answer

try this:

.......|sed 's@\\@@g'

or:

.......|sed "s@\\\\@@g"

EDIT add a test output:

kent$  echo "http:\/\/stackoverflow.com\/questions\/ask"|sed "s@\\\\@@g"
http://stackoverflow.com/questions/ask

kent$  echo "http:\/\/stackoverflow.com\/questions\/ask"|sed 's@\\@@g'  
http://stackoverflow.com/questions/ask