我有一个像这样的表的文件:
我已经完成了我的程序从我正在寻找的基因行中返回值(最大值、最小值和平均值)。现在我的目标是相同的,但用户将打印列号而不是单词。自我获得这些值,但只能从一列。
这是我的代码:
#!/bin/bash
FICHERO="affy.txt"
function OPTIONS
{
echo "_____________OPTIONS_____________"
echo ""
echo " 1. Select one gene and its test results"
echo " 2. Select one column and its test results"
echo " 3. Exit"
}
function gene
{
if [ -e "affy.txt" ]; then # Si el fichero existe...
echo "Print the name of the gene you are looking for: "
read -p "Name:" NAME
OLDIFS=$IFS
IFS=",";
# Calcular max, min y mean.
min=` grep -m1 "$NAME" affy.txt |tr -s ',' '.' | tr -s ' ' '\n' | cut -d' ' -f3- | sort -n | head -1`
max=` grep -m1 "$NAME" affy.txt | tr -s ' ' ' ' |tr -s ',' '.' | cut -d ' ' -f3- | tr -s ' ' '\n' | sort -n | tail -1`
mean=` grep -m1 "$NAME" affy.txt | tr -s ' ' ' ' |tr -s ',' '.' | cut -d ' ' -f3- | tr -s ' ' '\n' | awk '{sum+=$1} END {print sum/NR}'`
echo "Min value: "$min
echo "Max value: "$max
echo "Mean value: "$mean
else
echo "Invalid gene name!"
fi
echo
}
function column
{
if [ -e $FICHERO ]; then
echo "Print the column number you are looking for: "
read -p "Name: " NAME
else
echo "El fichero no existe o no contiene entradas en la agenda"
fi
}
opc=0
exit=5
while [ $opc -ne $exit ];
do
clear
OPTIONS # Dibujamos el menu en pantalla
read -p "Opcion:..." opc # Escogemos la opcion deseada
if [ $opc -ge 1 ] && [ $opc -le 5 ]; then
clear
case $opc in # Acciones para las diferentes opciones del menu
1)gene
;;
2)column
;;
esac
else
echo "Insert a correct option!!"
fi
echo "Press any key..."
read
done
选项 1 有效。
我在名为 column 的函数中尝试了类似的方法,但它不起作用......:
function column
{
if [ -s $FICHERO ]; then
echo "Print the column number you are looking for: "
read -p "column: " column
for i in "$column"
do
col+="${i#-}"","
echo "You are working with column number:" $col
done
else
echo "El fichero no existe o no contiene entradas en la agenda"
fi
if [ "$col" = "" ]; then
echo "Insert Columns please!"
else
for i in $col;
do
echo
echo minim columna= `tr -s ',' '.' affy.txt | tr -s ' ' '\n' | cut -d' ' -f"$col" | sort -n | head -1`
echo maxim columna "$i"= `grep "$col" affy.txt | tr -s ' ' ' ' |tr -s ',' '.' | cut -d ' ' -f"$i" | sort -n | tail -1`
echo average columna "$i"= `grep "$col" affy.txt | tr -s ' ' ' ' |tr -s ',' '.' | cut -d ' ' -f"$i" | awk '{sum+=$0} END {print sum/NR}'`
shift
done
fi