59

我正在尝试用单引号替换字符串中的所有双引号。这是我的表达:

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

不幸的是,只有第一个双引号被替换:S

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

有任何想法吗?

4

3 回答 3

114

您需要将g标志传递给sed

sed "s/\"/'/g"
于 2013-04-22T18:23:01.867 回答
59

You could use tr here, concise and less of quoting headache:

tr '"' "'"
于 2013-04-22T18:30:35.493 回答
3

This might work for you:

sed -i "y/\"/'/" hello.txt

-i option is used to edit in place on the file hello.txt.

于 2013-04-23T05:49:38.767 回答