【发布时间】:2015-08-13 22:10:12
【问题描述】:
我想编写一个 shell 脚本来合并给定目录中多个文件的内容。
DIR1 contains sample1.txt sample2.txt
sample1.txt contents :---this is sample1 file
sample2.txt contents :---this is sample2 file
DIR2 contains demo1.txt demo2.txt
demo1.txt contents :---this is demo1 file
我试过了:
(find /home/DIR1 /home/DIR2 -type f | xargs -i cat {} ) > /result/final.txt
成功了!
this is sample2 file this is sample1 file this is demo1 file
但是输出出现在一行中,我需要将每个文件的输出放在单独的新行中。 像这样:
this is sample1 file
this is sample2 file
this is demo1 file
如何做到这一点?
如有任何帮助,我们将不胜感激。
【问题讨论】:
-
我无法重现您的问题。您的示例在我的机器上运行良好。我不知道为什么在你的情况下输出打包成单行。
-
@mainframer 在他的情况下它的工作方式不同,因为原始文件不以换行符结尾