串联文件并在文件之间插入新行 [英] Concatenating Files And Insert New Line In Between Files
本文介绍了串联文件并在文件之间插入新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有多个文件要与cat
连接.
假设
I have multiple files which I want to concat with cat
.
Let's say
File1.txt
foo
File2.txt
bar
File3.txt
qux
我想进行合并,使最终文件看起来像这样:
I want to concat so that the final file looks like:
foo
bar
qux
代替通常的cat File*.txt > finalfile.txt
foo
bar
qux
什么是正确的方法?
推荐答案
您可以这样做:
for f in *.txt; do (cat "${f}"; echo) >> finalfile.txt; done
在运行上述命令之前,请确保文件finalfile.txt
不存在.
Make sure the file finalfile.txt
does not exist before you run the above command.
如果允许使用awk
,则可以执行以下操作:
If you are allowed to use awk
you can do:
awk 'FNR==1{print ""}1' *.txt > finalfile.txt
这篇关于串联文件并在文件之间插入新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文