Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove escape char from string in bash using sed?

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?

like image 595
user1581900 Avatar asked Oct 28 '25 18:10

user1581900


1 Answers

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
like image 157
Kent Avatar answered Oct 30 '25 09:10

Kent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!