我有这个循环,但它不起作用: - /
for i in *CCDSxBaseCov.bed
do SM=`(echo $i | sed 's/.bed//g')`; echo $SM
for chr in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 X Y M; do echo "-- chr$chr --"; bases=`(grep chr$chr "${SM}_hg19_EXONSxBaseCov.bed" | wc -l)`; echo "EXONS target length=$bases"; cov=`(grep chr$chr "${SM}_hg19_EXONSxBaseCov.bed" | awk '{sum+=$3} END {print sum}')`; echo "sum EXONS bases coverage=$cov"; avercov=$(($cov/$bases)); echo "EXONS average coverage=$avercov" >> ${SM}_hg19_EXONScovstats.txt
done
done
仅第二个循环工作
答案 0 :(得分:0)
注释内部,如果它自己工作并屏蔽$ i,因为它是一个文件名,可能包含空格。使用$(...)而不是弃用的反引号。
for i in *CCDSxBaseCov.bed
do SM=$((echo "$i" | sed 's/.bed//g')); echo $SM
# for chr in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 X Y M; do echo "-- chr$chr --"; bases=`(grep chr$chr "${SM}_hg19_EXONSxBaseCov.bed" | wc -l)`; echo "EXONS target length=$bases"; cov=`(grep chr$chr "${SM}_hg19_EXONSxBaseCov.bed" | awk '{sum+=$3} END {print sum}')`; echo "sum EXONS bases coverage=$cov"; avercov=$(($cov/$bases)); echo "EXONS average coverage=$avercov" >> ${SM}_hg19_EXONScovstats.txt
# done
done