Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace single quotes to double quotes in bash?

Tags:

bash

sed

ubuntu

i have a following string:

 {"name":"ram","details":[{'subjects':{'service_location':'c:/A.exe','url':'http://A.zip'}}]}

In the above string few strings have single quotes around them. so, how can i replace single quotes with double quotes in the above string and get as follows:

 {"name":"ram","details":[{"subjects":{"service_location":"c:/A.exe","url":"http://A.zip"}}]}
like image 680
Learner Avatar asked Dec 05 '25 06:12

Learner


2 Answers

@Learner: Try a sed solution:

sed "s/'/\"/g"  Input_file

OR

your_command | sed "s/'/\"/g" 
like image 115
RavinderSingh13 Avatar answered Dec 07 '25 21:12

RavinderSingh13


Extending @RavinderSingh13 answer, use following command to convert your string.

echo '{"name":"ram","details":'"[{'subjects':{'service_location':'c:/A.exe','url':'http://A.zip'}}]}" | sed "s/'/\"/g"
like image 22
MicroPyramid Avatar answered Dec 07 '25 20:12

MicroPyramid



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!