【发布时间】:2020-04-16 00:48:22
【问题描述】:
我正在尝试替换多行上的两个匹配模式,仅替换匹配的 start 和 end 行,并将行保留在 start 和 end 之间。
我尝试使用 sed、awk、Python、Perl 结合此处的一些答案,但没有运气。
这就是我所拥有的:
other text
```term
command1
```
other text
```term
command1
command2
```
other text
```js
code
```
替换后的文本应如下所示:
other text
{{< terminal >}}
command1
{{< /terminal >}}
other text
{{< terminal >}}
command1
command2
{{< /terminal >}}
other text
```js
code
```
基本上,我想用{{< /terminal >}} 替换每个匹配的包含term with `{{< terminal >}}` and 的行。
我无法进行简单的搜索并替换包含start 和end 模式的行,因为end 可以匹配我想要保留的其他start 行。
【问题讨论】:
-
抱歉,不清楚,能否请您在问题中发布更清晰的示例示例,然后让我们知道?
-
基本上我想用
{{< terminal >}}和 ``` 用 {{}} 替换包含 ``` 术语的每个匹配行。