如何从多个目录/文件夹合并多个文件
问题描述:
我有300个目录/文件夹,每个目录有两列单个文件(xxx.gz),我想合并所有文件夹中的所有文件在一个文件中。在所有文件中,第一列是相同的标识符(ID)。如何从多个目录/文件夹合并多个文件
如何将所有文件合并为单个文件?
而且我想将每列的标题作为相应目录中文件的名称。
目录名称是:(68a7eb0a-123,b5694957-764等)和文件名是:(a5c403c2,292c4a2f等), 目录名称和各自的文件名不一样,我想把文件名称作为头。
all directories
ls
6809b1c3-75a5
68e9b641-0cc9
71ae07b8-8bde
b7815cd2-1e69
..
..
each directory contain single file:
cd 6809b1c3-75a5
ls bd21dc2e.txt.gz
答
试试这个:
for i in * ; do for j in $i/*.gz ; do echo $j >> ../final.txt ; gunzip -c $j >> ../final.txt ; done ; done
注释版本:
for i in * # for each directory under current working directory
do # have nothing else in there
for j in $i/*.gz # for each gzipped file under directories
do
echo $j >> ../final.txt # echo path/file to the final file
gunzip -c $j >> ../final.txt # append gunzipping the file to the final file
done
done
结果:
$ head -8 ../final.txt
6809b1c3-75a5/bd21dc2e.txt.gz
blabla
whatever
you
have
in
those
files
请出示一个例子目录结构和文件内容和预期的最终文件。 –
[阅读所有文件](http://*.com/questions/11433432/importing-multiple-csv-files-into-r)然后[在列表中合并多个data.frames](http:// *的.com /问题/ 8091303 /同时合并多数据帧-IN-A-列表)。此解决方案应该根据文件大小和内存而工作。 – zx8754
@mona请使用[“编辑”](http://*.com/posts/38660539/edit)以更多信息更新您的文章。 – zx8754