在新文件中的文件内容后插入空行

Insert empty line after the contents of a file in a new file

这是一个简单的问题,我只是坚持下去。我正在获取一堆不同文件的内容,并将每个文件的名称打印为 header 在其内容之前。这么多工作。但是我想要一个空行来分隔一个文件的内容和下一个文件内容的header。

我希望它看起来像:

File 1 header

File 1 contents

[empty space]

File 2 header

File 2 contents

我尝试在我的代码中将 \n 放在“{}”之后,但这没有用。有什么建议吗?

find . -type f -name '*_top_hits.txt' -print -exec cat {} \; > combinedresults.txt

您可以尝试添加第二个 -exec:

find . -type f -name '*_top_hits.txt' -print -exec cat {} \; -exec echo \; > combinedresults.txt

这样做的一个副作用是在最后一个文件的内容之后会在末尾添加一个新行。

您可以将一个空的 echo 作为 find -exec 的一部分作为

find . -type f -name "*_top_hits.txt" -print -exec sh -c "cat {};echo"  \; > combinedresults.txt

echo 仅在每个文件内容后生成一个空的换行符。此外,您不需要多个 -exec 选项,而是使用单个子 shell.