将字符串“//”替换为与“///”使用外壳

发布于 2024-12-29 11:35:46 字数 773 浏览 2 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

逆光下的微笑 2025-01-05 11:35:46

尝试:

sed -i 's+//+///+g' *.txt

如果需要用 /// 代替 // xD,那么使用 / 作为分隔符是不吉利的。

Try:

sed -i 's+//+///+g' *.txt

It is unlucky to use / as a delimiter if you need to substitute /// for // xD.

装迷糊 2025-01-05 11:35:46

使用strrep()字符串替换)。
我假设变量“s”包含包含“//”的字符串。在脚本中添加以下代码:

strrep (s,"//","///");

在本例中, / 充当 /// 的转义序列。

Use strrep() (string replace).
I am assuming variable "s" contains your string containing "//". Add the following code in your script:

strrep (s,"//","///");

In this case / acts as escape sequence for / and // .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文