【发布时间】:2021-08-24 05:17:53
【问题描述】:
我在 Markdown 编写的教程中使用了一种独特的风格来演示代码。
使用 GitHub 代码块中的新“复制”按钮(截至 21 年 5 月),我想更改我的所有内联命令以阻止 console 代码,从而使我的教程对学生来说更容易。
(如果您愿意,欢迎您查看实际教程:VIP Linux)
我的问题
34 可以是任何数字、字母或连字符
评论可能存在也可能不存在
所有文件都以.md结尾
我想改变这个:
| **34** :$ `one cli command here` Optional `code` comment, *maybe* with <kbd>Ctrl</kbd> + <kbd>Z</kbd>
...到这个:
| **34** :$ Optional `code` comment, *maybe* with <kbd>Ctrl</kbd> + <kbd>Z</kbd>
```console
one cli command here
```
我的研究
我可以轻松地使用sed 进行部分操作
sed 's/** :$ `/** :$\n```console\n/' *.md | sed 's:` :\n```\n\n:'
变化:
| **10** :$ `some command` Some `code` *comment*
...到:
| **10** :$
```console
some command
```
Some `code` *comment*
但是,我需要 Some code *comment* 与 | **10** :$ 保持在同一行
我为什么要问
这可能是awk 的工作。即使我理解awk,必要的正则表达式也让我望而却步。
我可以在最后的sed 语句中使用文本占位符,然后使用grep 手动更改Optional code *comments*。但是,我更愿意为社区贡献一个问题,这也可以节省我的时间。
【问题讨论】: