【发布时间】:2015-06-29 13:52:14
【问题描述】:
我有一个看起来像这样的文本文件:
Some text here. This text is not replaced.
---
And then a wild block appears!
It has stuff in it that I'm trying to replace.
---
The block is no more. Nothing to replace here.
还有另一个要插入内容的文本文件:
A multi-
line thing to replace.
This block is not demarcated
in the same way
as the other
而我要做的是用文本文件的内容替换----demarcated 块,使其看起来像这样:
Some text here. This text is not replaced.
A multi-
line thing to replace.
This block is not demarcated
in the same way
as the other
The block is no more. Nothing to replace here.
这类似于this question,但我认为这并不适用,因为我正在处理的是一个多行块,而sed 似乎并不擅长于此。 awk 或 ruby 或其他东西可以这样做吗?
【问题讨论】:
-
那个问题是关于插入文本的,但是替换多行块有点困难。由于这些 sed 操作在单行上运行,因此需要一些其他方法。
-
是的,是的。可能将其与sed insert file content after specific pattern match 合并即可。我只是将其评论为帮助者,而不是近距离投票。
-
不幸的是,第二个问题只涉及插入文本,而不是替换文本。