首页 > 解决方案 > 解析来自多个文件夹的文本文件并创建新的 [shell]

问题描述

我有这个文件夹结构......

171219_NB501241_0070_AHCHYNBGX5
├── fastq
│   ├── Reports
│   ├── Stats
│   ├── Undetermined_S0_R1_001.fastq.gz
│   └── Undetermined_S0_R2_001.fastq.gz
├── Logs
│   └── Logs.zip
├── Recipe
│   └── NS2932577-REAGT.xml
├── RTAComplete.txt
├── RTAConfiguration.xml
└── samplesheet.R70.csv
180201_NB501241_0088_AHJ2GHBGX5
├── fastq
│   ├── Reports
│   ├── Stats
│   ├── Undetermined_S0_R1_001.fastq.gz
│   └── Undetermined_S0_R2_001.fastq.gz
├── Logs
│   └── Logs.zip
├── Recipe
│   └── NS2951235-REAGT.xml
├── RTAComplete.txt
├── RTAConfiguration.xml
└── samplesheet.R88.csv

...里面有一个文本文件Stats,我想从中读取一些特定的行并在每个fastq文件夹(17121.../fastq/)中生成一个新的文本文件。

运行这些代码行...

for i in 70 88
>do cat *0${i}*/fastq/Stats/DemultiplexingStats.xml | grep -e "<Sample name" -e "<BarcodeCount" >> *0${i}*/fastq/rawcounts2
>done

...我遇到了这个错误,我不知道我在考虑什么(如果文本重定向在循环结束时效果很好,但我想要每个文件夹都有一个特定的文件):

-bash: *070*/fastq/rawcounts2: No such file or directory
-bash: *088*/fastq/rawcounts2: No such file or directory

谢谢。

标签: bashshellloops

解决方案


尝试以下操作:

find . -path "*/fastq/Stats/DemultiplexingStats.xml" -execdir grep -e "<Sample name" -e "<BarcodeCount" '{}' >> ../rawcounts2 \;

查找所有以“/fastq/Stats/DemultiplexingStats.xml”结尾的文件,然后在找到的文件目录中,对找到的文件执行 grep 命令,并输出到当前目录上一级目录中的 rawcounts2 文件。


推荐阅读