如何在换行符上连接两个文件?

How do I join two files on a newline?

当我运行cat 1.txt 2.txt > result.txt时,我希望result.txt1.txt内容的结尾和[=内容的开头之间有一个换行符13=]。我该怎么做?

众多选项之一是:

echo | cat 1.txt - 2.txt > result.txt

- 参数表示 'accept standard input' 并且 echo 提供新行

此选项仅适用于 2 个文件。如果您实际上正在查看许多文件等,那么例如:

(cat 1.txt; echo; cat 2.txt; echo; cat 3.txt) > result.txt

会起作用;值得注意的是,这会产生更多的 cat 进程。