如何运行一个程序文件中的每一行

问题描述 投票:0回答:1

我有一个文件,如file.txt的:

Specie1
Specie2
Specie3

我有一个计划,这3种运行,它被称为bedtools getfasta

所以,我有想法是要做到:

cat file_species.txt |
while read line; do 
    bedtools getfasta -fi /path/${line}/${line}.fa -bed /path/${line}/Recover_fasta.bed -s -fo /path/${line}/Fasta_loci_seq.fa" ;
done

如果我做一个echo我得到:

bedtools getfasta -fi /path/Specie1/Specie1.fa -bed /path/Specie1/Recover_fasta.bed -s -fo /path/Specie1/Fasta_loci_seq.fa" ;
done
bedtools getfasta -fi /path/Specie2/Specie2.fa -bed /path/Specie1/Recover_fasta.bed -s -fo /path/Specie1/Fasta_loci_seq.fa" ;
done
bedtools getfasta -fi /path/Specie3/Specie3.fa -bed /path/Specie1/Recover_fasta.bed -s -fo /path/Specie1/Fasta_loci_seq.fa" ;
done

如果我刚刚过去的这些代码的作品,但我怎么能只执行它在我的第一个剧本后"do"而不是做一个回声,然后粘贴代码?

bash
1个回答
0
投票

摆脱尾随双引号和分号结束,并与${line}替换"$line"

cat file_species.txt |
while read line; do 
    bedtools getfasta -fi /path/"$line"/"$line".fa -bed /path/"$line"/Recover_fasta.bed -s -fo /path/"$line"/Fasta_loci_seq.fa
done
© www.soinside.com 2019 - 2024. All rights reserved.