![在 shell 脚本中合并不同文件内容时出现空行](https://linux22.com/image/1710284/%E5%9C%A8%20shell%20%E8%84%9A%E6%9C%AC%E4%B8%AD%E5%90%88%E5%B9%B6%E4%B8%8D%E5%90%8C%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9%E6%97%B6%E5%87%BA%E7%8E%B0%E7%A9%BA%E8%A1%8C.png)
我已经编写了 shell 脚本来合并不同文件的内容,我已经创建了目录 f1、f2、d1、d2 及其下的文件,我需要合并所有文件的内容:命令是
find /home/ah5024331/f1 /home/ah5024331/f2 /home/ah5024331/d1 /home/ah5024331/d2 /home/ah5024331/f1 /home/ah5024331/f2 /home/ah5024331/d2 -type f -exec cat {} \; -exec echo \; > /home/ah5024331/op.txt
输出为:
--this is new text from f1 ----
--this is text from f2 ----
--this is new text from d1 ---
---this is new text from d2 ---
--this is new text from f1 ----
--this is text from f2 ----
---this is new text from d2 ---
在文件 f1 内容之后,它添加了一个空行。我希望合并的内容中间没有任何空行。我需要在上述命令中做哪些更改?任何帮助都将不胜感激。
答案1
如果在 Linux 中运行,下面的脚本应该可以工作。请告诉我您在哪个 Unix 操作系统上运行此脚本。
find /home/ah5024331/f1 /home/ah5024331/f2 /home/ah5024331/d1 /home/ah5024331/d2 /home/ah5024331/f1 /home/ah5024331/f2 /home/ah5024331/d2 -type f -exec cat {} \; -exec echo -n "" \; > /home/ah5024331/op.txt