我需要使用'vi'和/或'sed'编辑器在每行下面插入一个文本块。需要在每行下面插入的文本块如下(表示空行):
first line.
second line.
...
n-th line.
<empty line>
在插入之前,文本将如下所示:
This is the first line.
This is the second line.
...
This is the last line.
插入后,文本如下所示:
This is the first line.
first line.
second line.
...
n-th line.
<empty line>
This is the second line.
first line.
second line.
...
n-th line.
<empty line>
...
This is the last line.
first line.
second line.
...
n-th line.
<empty line>
任何?谢谢。
答案 0 :(得分:0)
假设要插入的块文本保存在名为block
的文件中,您要处理的文件名为file
:
gnu sed:
sed -r '/^/r block' file
答案 1 :(得分:0)
这是awk
版本。
awk '{$0=$0"\n first line.\n second line.\n ...\n n-th line.\n"}1' file
This is the first line.
first line.
second line.
...
n-th line.
This is the second line.
first line.
second line.
...
n-th line.
...
first line.
second line.
...
n-th line.
This is the last line.
first line.
second line.
...
n-th line.
答案 2 :(得分:0)
This is the first line. This is the second line. ... This is the last line.
first line. second line. ... n-th line.
在此之后,宏的美丽开始了。
现在你在文件的原始第二行。输入 @a 。您将在原始第二行下方找到添加的文本块,并将光标移动到原始第三行。
或者,如果您知道原始文件有n行。你可以输入 n-1 @ a 。文本块将添加到所有行下方。