遍历.tar.gz目录并连接文件(无需解压缩文件夹)
作者:互联网
我有一个约20000 tar.gz目录的文件夹,每个目录包含一堆文件.我想进入源文件夹,遍历tar.gz目录(不解压缩)并连接文件,因此最后我将拥有三个大文件.
例如我有一个具有.tar.gz目录的根文件夹pnoc,每个压缩文件夹都有三个文件夹-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)
谢谢!
解决方法:
使用bash find命令如下: exec中的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
标签:bash,shell,find,python,r 来源: https://codeday.me/bug/20191118/2027237.html