2016-07-22 58 views
0

bash脚本的下面部分,用户从目录中选择一个文件。使用在bash过程中选择的相同文件

select file in $(cd /home/cmccabe/Desktop/NGS/API/5-14-2016/bedtools;ls);do break;done 

目录中的文件

123_base_counts.txt 
456_base_counts.txt 
789_base_counts.txt 

bash秒部分目前(用户手动选择文件)

select file in $(cd /home/cmccabe/Desktop/NGS/API/5-14-2016/bedtools;ls);do break;done 

我所试图做的是,如果用户在第一个select中选择123_base_counts.txt,然后在第二个选择文件的任何名称,使用以123开头的那个。

该目录中的第二select有文件名:

123_variant_strandbias_readcount.vcf.hg19_multianno_removed_final (this one is automatically selected because it has the same starting digits as the original file) 
456_variant_strandbias_readcount.vcf.hg19_multianno_removed_final 
789_variant_strandbias_readcount.vcf.hg19_multianno_removed_final 

我可以手动select每个文件,但我不知道如何自动选择。谢谢 :)。

回答

1

数字部分后面的文件名是否总是有下划线? 如果是这样你可以做到以下几点

nameNumeric=$(echo $file | awk -F'_' '{print $1}'); 
secondFile=$(ls /home/cmccabe/Desktop/NGS/API/5-14-2016/bedtools/${nameNumeric}*); 
+0

也就是说在数字部分之后总会有一个'_'。谢谢 :)。 – Chris

+0

非常感谢:)。 – Chris

相关问题