如何在UNIX中合并和删除文件? [英] How to merge and delete the files in unix?
本文介绍了如何在UNIX中合并和删除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在bash中将多个文件合并为单个文件.所以我使用代码,
i would like to merge multiple files into single file in bash. so i use the code,
cat file1 file2 file3 file4 >>输出
cat file1 file2 file3 file4 >> output
但是由于我的计算机内存不足,所以无法创建合并文件.相反,您是否知道一旦将数据添加到输出文件中后如何同时删除file1 file2 file3?
But because my computer has low memory i am not able to create the merged file. instead do you know how to simultaneously remove file1 file2 file3 once the data has been added to output file?
推荐答案
for i in file1 file2 file3 file4 ; do cat "$i" >> output && rm "$i" || break ; done
因此,对于每个文件,它将把内容附加到 output
并在附加后删除源文件.如果有任何问题,它将停止.
So for each file, it will append the contents to output
and remove the source file once appended. If anything goes wrong, it stops.
这篇关于如何在UNIX中合并和删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文