本文介绍了遍历linux中标题不同的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想遍历Linux目录中的几个文件,如下所示:

I would like to iterate over several files in my directory in linux which look like this:

SRR057629_1.fastq.gz SRR057629_2.fastq.gz SRR057630_1.fastq.gz
SRR057630_2.fastq.gz SRR057631_1.fastq.gz SRR057631_2.fastq.gz
SRR057632_1.fastq.gz SRR057632_2.fastq.gz SRR057633_1.fastq.gz
SRR057633_2.fastq.gz

对我来说,挑战是我需要将 SRR ..._ 1 SRR ..._ 2 作为一个命令(tophat2)的输入,然后再使用下一个同一命令的几个 SRR *** _ 1 SRR *** _ 2 .原则上,它看起来像这样:

The challenge for me is that I would need SRR..._1 and SRR..._2 as input for one command (tophat2) and thereafter take the next couple of SRR***_1 and SRR***_2 for the same command. In principle it would look like this:

tophat2 -G /Homo_sapiens/UCSC/hg19/Annotation/Genes/genes.gtf /Homo_sapiens /UCSC/hg19/Sequence/Bowtie2Index/genome SRR057636_1.fastq.gz SRR057636_2.fastq.gz
tophat2 -G /Homo_sapiens/UCSC/hg19/Annotation/Genes/genes.gtf /Homo_sapiens/UCSC/hg19/Sequence/Bowtie2Index/genome SRR057637_1.fastq.gz SRR057637_2.fastq.gz

那么我该如何为每个命令更改这些数字(粗体)?

So how could I change these numbers (bold) for each command??

SRR0576**29**_1.fastq.gz

SRR0576**29**_1.fastq.gz

最良好的祝愿,西蒙

推荐答案

for a in *_1.fastq.gz; do
   tophat2 -G /Homo_sapiens/UCSC/hg19/Annotation/Genes/genes.gtf /Homo_sapiens /UCSC/hg19/Sequence/Bowtie2Index/genome $a ${a/_1/_2}
done

这篇关于遍历linux中标题不同的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 15:40