linux - 连接文件并在文件之间插入新行

我有多个文件要与 cat 连接。 比方说

File1.txt 
foo

File2.txt
bar

File3.txt
qux

我想连接,使最终文件看起来像:

foo

bar

qux

用通常的 cat File*.txt > finalfile.txt

代替这个
foo
bar 
qux

正确的做法是什么?

最佳答案

你可以这样做:

for f in *.txt; do (cat "${f}"; echo) >> finalfile.txt; done

在运行上述命令之前,请确保文件 finalfile.txt 不存在。

如果你被允许使用 awk 你可以这样做:

awk 'FNR==1{print ""}1' *.txt > finalfile.txt

https://stackoverflow.com/questions/8183191/

相关文章:

linux - Linux 上的 PostgreSQL 数据库默认位置

python - Pandas 重采样文档

Python请求 - 打印整个http请求(原始)?

python - Python NumPy 中的 np.mean() 与 np.average()?

linux - 我可以使用 GDB 调试正在运行的进程吗?

python - 在 Python 中格式化多行 dict 的正确方法是什么?

python - 检查数字是 int 还是 float

linux - 如何根据字段的数值对文件进行排序?

linux - 如何将 AWS CLI 升级到最新版本?

linux - 如何在 Bash 中列出每个文件和目录的大小并按大小降序排序?