Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace all double quotes with single quotes

Tags:

sed

I'm trying to replace all double quotes in a string with single quotes. here my expression:

echo "<a href=\"#\" id=\"resendActivationMailLink\">here</a>" | sed "s/\"/'/" 

unfortunately only the first double quote is replaced :S

<a href='#" id="resendActivationMailLink">here</a>  

any Ideas?

like image 521
Zounadire Avatar asked Apr 22 '13 18:04

Zounadire


People also ask

Why use single quotes instead of double quotes?

In America, Canada, Australia and New Zealand, the general rule is that double quotes are used to denote direct speech. Single quotes are used to enclose a quote within a quote, a quote within a headline, or a title within a quote.

Are single and double quotes interchangeable?

The short answer is that it depends on the country that you are writing in. In British and Australian English, one typically uses single quotes. If you're writing in North America, double quote marks are typically used.

How do you change double quotes into single quotes in SQL?

Backspace over the double quotes and then type a single quote.

How do you replace a double quote in a string?

If you want to add double quotes(") to String, then you can use String's replace() method to replace double quote(") with double quote preceded by backslash(\").


1 Answers

You need to pass the g flag to sed:

sed "s/\"/'/g" 
like image 108
Tim Cooper Avatar answered Sep 20 '22 13:09

Tim Cooper