2

这里的初学者试图让管道在 bash 中工作。如果有人可以看到为什么当我运行以下命令时,我会得到:

-bash: `$i': not a valid identifier,

那真的很有帮助。另外如果有其他错误请告诉我

for $i in /home/regionstextfile; do tabix /sequences/human_variation/snps/genotypes.vcf.gz $i | vcftools --window-pi 10000 >> /home/Testgenomesdata/genomesregions.txt; done

这个想法是为区域文本文件(包含基因组坐标)中的每一行运行一个在文件中调用tabixvcf.bz程序,然后使用vcftools指定选项运行输出,然后将所有输出放入genomesregions.txt文件中。

4

2 回答 2

8

一定是这样的:

for i in `</home/regionstextfile`
do 
  tabix /sequences/human_variation/snps/genotypes.vcf.gz $i | vcftools --window-pi 10000 >> /home/Testgenomesdata/genomesregions.txt
done

当你使用一个变量时(例如给它赋值或导出它,或者除了变量本身做任何事情)你写它的名字时不带$; 当您使用您编写的变量的值时$

编辑:

当区域名称包含空格但每个区域位于单独的行中时,您需要while

cat /home/regionstextfile | while read i
do 
  tabix /sequences/human_variation/snps/genotypes.vcf.gz "$i" | vcftools --window-pi 10000 >> /home/Testgenomesdata/genomesregions.txt
done
于 2012-06-19T07:37:55.643 回答
1

没有 cat 相同的事情:

while read i
do
  tabix /sequences/human_variation/snps/genotypes.vcf.gz "$i" | vcftools --window-pi 10000 >> /home/Testgenomesdata/genomesregions.txt
done < /home/regionstextfile

除非 IFS='' 否则备注<file.txt无法工作

OLDIFS="$IFS"
IFS=''
for i in `</home/regionstextfile`
do
  tabix /sequences/human_variation/snps/genotypes.vcf.gz $i | vcftools --window-pi 10000 >> /home/Testgenomesdata/genomesregions.txt
done
IFS="$OLDIFS"
于 2012-06-19T09:49:01.373 回答