cancel
Showing results for 
Search instead for 
Did you mean: 

How to replace " by \"

SOLVED
Go to solution
Leo The Cat
Regular Advisor

How to replace " by \"

Hi Guys

How to replace " by \"

Bests Regards
Den
5 REPLIES
Matti_Kurkela
Honored Contributor

Re: How to replace " by \"

In what context?

For example:
$ echo 'by \' | sed -e 's!by \\!something else!g'
something else

MK
MK
Leo The Cat
Regular Advisor

Re: How to replace " by \"

Hummm example:

Signal=$(myfunccall)

echo $Signal
=> Dump Event "user" sending

java -jar myclass.jar "$Signal_information"
=> I want to have only one parameter here like this

=> Dump Event \"user\" sending


Bests regards
Den
Ivan Ferreira
Honored Contributor
Solution

Re: How to replace " by \"

$ Signal='Dump Event "user" sending'
$ echo $Signal
Dump Event "user" sending
$ echo $Signal | sed 's/"/\\"/g'
Dump Event \"user\" sending


Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Leo The Cat
Regular Advisor

Re: How to replace " by \"

Ivan solution is efficient !
Thanks a lot.
Mike Stroyan
Honored Contributor

Re: How to replace " by \"

The bash printf builtin has a %q format to quote strings for reuse by bash.
It may work well with other parsers.
It will backslash quote characters like spaces, quotes, and ampersands.
Here is an example with %s and %q formats.

$ printf "%s\n" 'try "double quoted" + '"'"'single quoted'"'"' & \t backquoted text'
try "double quoted" + 'single quoted' & \t backquoted text
$ printf "%q\n" 'try "double quoted" + '"'"'single quoted'"'"' & \t backquoted text'
try\ \"double\ quoted\"\ +\ \'single\ quoted\'\ \&\ \\t\ backquoted\ text