bash - 解析来自多个文件夹的文本文件并创建新的 [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
谢谢。
解决方案
尝试以下操作:
find . -path "*/fastq/Stats/DemultiplexingStats.xml" -execdir grep -e "<Sample name" -e "<BarcodeCount" '{}' >> ../rawcounts2 \;
查找所有以“/fastq/Stats/DemultiplexingStats.xml”结尾的文件,然后在找到的文件目录中,对找到的文件执行 grep 命令,并输出到当前目录上一级目录中的 rawcounts2 文件。
推荐阅读
- node.js - 在 Azure 上调用 nodejs API 的连接关闭错误
- linux - 如何根据字数在第一个句点字符处拆分行并在结果行中重复该过程(在模式空间中)
- javascript - 避免在使用不受支持的 HTML 功能时产生错误
- java - sdkmanager 返回相同的输出,而不管传递给它的参数是什么
- kubernetes - 如何使用 kubectl 标签重新标记 k8s 中的多个 pod?
- typescript - 用 setTimeout 承诺
- python-3.x - pd.to_sql 返回 KeyError: '\x02' on Windows Server 2008 R2 (Python 3.6.4) (Pandas 0.25)
- sqlite - Xamarin MVVM 从另一个页面删除 Listview 项目
- android - 如何进行这样的对话?
- apache-spark - Spark 中的用户定义函数 (UDF) 是否在集群工作节点上并行运行?