我知道这听起来像是在逃避,但是当字符串中有单引号和双引号时,我永远不可能让 sed 工作。为了帮助像我这样有困难的新手,一个选择是分开字符串。我必须替换超过100个 index.hmtl 文件中的代码。字符串同时有单引号和双引号,所以我只是将字符串分开,并将第一个块替换为
<!-- and the second block with -->. It made a mess of my index.html files but it worked.
$ cat testfile
"it's more than ones thing"
$ sed -i "s/\"it's more than ones thing\"/it's more than one's thing/" testfile
$ cat testfile
it's more than one's thing