将字符串“//”替换为与“///”使用外壳
我正在尝试使用 doxygen 生成 Octave API 的文档。但是,doxygen 仅将 ///
之后的注释识别为文档,并且 Octave 中的注释样式仅使用 //
。我决定运行 shell 命令来更改此设置,并
sed -i 's/old-word/new-word/g' *.txt
从 此处。 测试命令时
sed -i 's/////// /g' *.txt
当我使用or
sed -i 's/"//"/"/// "/g' *.txt
,分别收到错误:
sed: -e expression #1, char 5: unknown option to `s'
or
sed: -e expression #1, char 6: unknown option to `s'
。如何正确使用 sed
将 //
替换为 ///
?
或者,是一种更简单的方法,例如在某些 IDE 中同时打开所有文件并重构。
I am trying to generate documentation of the Octave API using doxygen. However, doxygen recognizes only comments after ///
to be documentation and the comment style in Octave is to use only //
. I decided to run a shell command to change this and found this
sed -i 's/old-word/new-word/g' *.txt
from here. When I test the command using
sed -i 's/////// /g' *.txt
or
sed -i 's/"//"/"/// "/g' *.txt
I get the error:
sed: -e expression #1, char 5: unknown option to `s'
or
sed: -e expression #1, char 6: unknown option to `s'
respectively. How do I correctly use sed
to replace //
with ///
?
Alternatively, is a simpler way, such as, for example, opening all the files simuntaniously in some IDE and refactoring.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
如果需要用 /// 代替 // xD,那么使用 / 作为分隔符是不吉利的。
Try:
It is unlucky to use / as a delimiter if you need to substitute /// for // xD.
使用
strrep()
(字符串替换)。我假设变量“s”包含包含“//”的字符串。在脚本中添加以下代码:
在本例中,
/
充当/
和//
的转义序列。Use
strrep()
(string replace).I am assuming variable "s" contains your string containing "//". Add the following code in your script:
In this case
/
acts as escape sequence for/
and//
.