这段代码是为了给我在我想要的基因中输入的列的最大值、最小值和平均值。
因此,举个例子:“./script.sh 7 8 9 -g TAGLN” 这个代码将给出基因 TAGLN 的第 7 8 9 列的最大值、最小值和平均值。
这里的问题是函数 output2() 的平均值给出了错误的结果......但是,函数 output1() 的平均值很好,我无法理解......
#!/bin/bash
output1() {
var1=$(cat affy.txt | cut -d"!" -f$i | sort -nr | head -1)
echo "Maximum value of array ARRY$(($i-5|bc))X is $var1"
var2=$(cat affy.txt | cut -d"!" -f$i | sort -nr | tail -1)
echo "Minimum value of array ARRY$(($i-5|bc))X is $var2"
var3=$(cat affy.txt | cut -d"!" -f$i | awk '{total += $1; count++ } END {print total/count}')
echo -e "Average of array ARRY$(($i-5|bc))X is $var3 \n"
}
output2() {
var1=$(grep $word affy.txt | cut -d"!" -f$i | sort -nr | head -1)
echo "Maximum value of array ARRY$(($i-5|bc))X in gene $word is $var1"
var2=$(grep $word affy.txt | cut -d"!" -f$i | sort -nr | tail -1)
echo "Minimum value of array ARRY$(($i-5|bc))X in gene $word is $var2"
var3=$(grep $word affy.txt | cut -d"!" -f$i | awk '{total += $1; count++ } END {print total/count}')
echo -e "Average of array ARRY$(($i-5|bc))X in gene $word is $var3 \n"
}
function3() {
columns=""
for i in $@; do
if [ $i = "-g" ]; then
word=$2
is_there_g="True"
break
else
is_there_g="False"
fi
columns+="$i "
shift
done
length="${#columns}"
echo $columns
}
deciding_the_output() {
function3 $@
if [ $# = 0 ]; then
for i in `seq 5 20`; do
output1 $i
done
else
if [ $is_there_g = "False" ]; then
for i in $columns; do
output1 $i
done
else
if [ $length = 0 ]; then
for i in `seq 5 20`; do
output2 $i
done
else
for i in $columns; do
output2 $i
done
fi
fi
fi
}
deciding_the_output $@