我有一个大约20000个tar.gz目录的文件夹,每个目录包含一堆文件。我想进入源文件夹,遍历tar.gz目录(不解压缩)并连接文件,最后我将有三个大文件。
例如我有一个根文件夹pnoc
,其中包含.tar.gz
个目录,每个压缩文件夹有三个文件夹 - Kallisto
,RSEM
和Hugo
。我有一个未压缩的目录,看起来像这样:
pnoc/
├── C021_0001_20140916_tumor_RNASeq.tar.gz
├── C021_0002_001113_tumor_RNASeq.tar.gz
├── C021_0003_001409_tumor_RNASeq.tar.gz
├── C021_0004_001418_tumor_RNASeq.tar.gz
├── C021_0005_001661_tumor_RNASeq.tar.gz
├── C021_0007_001669_tumor_RNASeq.tar.gz
├── C021_0008_001699_tumor_RNASeq.tar.gz
├── C021_0009_001766_tumor_RNASeq.tar.gz
├── C021_0010_001774_tumor_RNASeq.tar.gz
├── C021_0011_001786_tumor_RNASeq.tar.gz
├── C021_0012_001825_tumor_RNASeq.tar.gz
├── C021_0013_001872_tumor_RNASeq.tar.gz
├── CPBT_0001_1_tumor_RNASeq.tar.gz
├── CPBT_0003_1_tumor_RNASeq.tar.gz
├── CPBT_0004_1_tumor_RNASeq.tar.gz
├── CPBT_0005_1_tumor_RNASeq.tar.gz
├── CPBT_0006_1_tumor_RNASeq.tar.gz
├── CPBT_0007_1_tumor_RNASeq.tar.gz
├── CPBT_0008_1_tumor_RNASeq.tar.gz
├── CPBT_0009_1_tumor_RNASeq.tar.gz
├── IMPROPERLY_PAIRED.C021_0006_001666_tumor_RNASeq.tar.gz
└── pnoc-manifest
C021_0001_20140916_tumor_RNASeq
├── Kallisto
│ ├── C021_0001_20140916_tumor_RNASeq.abundance.h5
│ ├── C021_0001_20140916_tumor_RNASeq.abundance.tsv
│ └── C021_0001_20140916_tumor_RNASeq.run_info.json
└── RSEM
├── C021_0001_20140916_tumor_RNASeq.rsem.genes.norm_counts.tab
├── C021_0001_20140916_tumor_RNASeq.rsem.genes.raw_counts.tab
├── C021_0001_20140916_tumor_RNASeq.rsem.isoform.norm_counts.tab
├── C021_0001_20140916_tumor_RNASeq.rsem.isoform.raw_counts.tab
├── C021_0001_20140916_tumor_RNASeq.rsem_genes.results
├── C021_0001_20140916_tumor_RNASeq.rsem_isoforms.results
└── Hugo
├── C021_0001_20140916_tumor_RNASeq.rsem.genes.norm_counts.hugo.tab
├── C021_0001_20140916_tumor_RNASeq.rsem.genes.raw_counts.hugo.tab
├── C021_0001_20140916_tumor_RNASeq.rsem.isoform.norm_counts.hugo.tab
├── C021_0001_20140916_tumor_RNASeq.rsem.isoform.raw_counts.hugo.tab
├── C021_0001_20140916_tumor_RNASeq.rsem_genes.hugo.results
└── C021_0001_20140916_tumor_RNASeq.rsem_isoforms.hugo.results
所以我想将所有* .abundance.tsv连接在一起,* .rsem.genes.norm_counts.tab连接在第二个文件中,* .rsem_genes.hugo.results连接在第三个文件中。最好和最有效的方法是什么?我对任何事情都没关系 - R
,Python
或Bash
。
$ find --version
find (GNU findutils) 4.5.11
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION SELINUX FTS(FTS_CWDFD) CBO(level=2)
谢谢!
答案 0 :(得分:3)
使用bash
find
命令,如下所示; cat
中的exec
命令应用于该命令返回的所有文件。 +
选项是为了确保shell生成cat
的实例不超过一个。
这里{}
表示返回find命令的文件。请参阅有关find -exec
find . -type f -name '*.abundance.tsv' -exec cat "{}" + >> ../AbundanceTSV.tsv
find . -type f -name '*.rsem.genes.norm_counts.tab' -exec cat "{}" + >> ../GenesNormCounts.tab
find . -type f -name '*.rsem_genes.hugo.results' -exec cat "{}" + >> ../HugoResults.results