在bash中将文本插入空白行 [英] Insert text into blank lines in bash
本文介绍了在bash中将文本插入空白行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用bash将文本按顺序插入txt中的空白行(txt文件可以包含数百个项目)?
It's possible to insert text in order into the blank lines in txt (txt file can contain hundreds of items) use bash?
第一个文件
text1
text2
text3
text4
textn...
#and etc
第二个文件
text1b
text2b
text3b
textbn...
#and etc
输出:
text1
text1b
text2
text2b
text3
text3b
text4
textbn...
textn...
#and etc
推荐答案
使用GNU sed和这两个文件:
With GNU sed and this two files:
文件1:
text1
text2
text3
text4
文件2:
text1b
text2b
text3b
此命令:
sed -e '/^$/{R file2' -e 'd}' file1
输出
text1
text1b
text2
text2b
text3
text3b
text4
来自man sed
:
R filename
:追加从文件名读取的行.每次调用该命令都会从文件中读取一行.这是GNU扩展.
R filename
: Append a line read from filename. Each invocation of the command reads a line from the file. This is a GNU extension.
这篇关于在bash中将文本插入空白行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文