0

我从 bash 代码开始,我对一个脚本有点迷茫。首先,我想说我已经阅读了这篇文章 Parse Args that are not declared但它没有帮助我。

我有一个包含 9 列和 6 行的文件 (affy.txt)。第一列是基因的名称,其他是来自实验的数值。我的目标是仅从所有基因之一的结果中计算最大值、最小值和平均值(ej:名为 ABC 的基因 2)。此外,我也想仅从一列中估计最大值、最小值和平均值。

我已经创建了一些代码...

#!/bin/bash
echo This script runs the follow options over affy.txt

echo OPTIONS:
echo   -a   Find a gene and its tests\' result
echo   -b   Analyze one column\'s result

echo Write an option, and beside it, the name of the gene or the number of the column you are looking \for:
read OPTION

for arg; do 
    case "$1" in $OPTION
    -a) shift
        grep -n $1 affy.txt;;
        gene="$1";;
    -b) shift
        [0-9]*) col+="${1#-}"",";;
        #I'm not sure if -b) sintaxys it's ok  
    esac
    shift 
done
echo col="$col" gene="$gene"

现在我只专注于它。我为下一步创建了一个代码,即估计基因或列的最大值、最小值和平均值。不过我现在不管了,写在这里是为了帮助大家理解脚本的思路。

#if [ "$col" = "" ]; 

    #then echo "Insert Columns please!"



#else

    #for i in $col; do  

    #echo

    #echo minim columna "$i"= `grep "$gene" affy.txt | cut -d ' ' -f"$i" | sort -n | head -1`
    #echo maxim columna "$i"= `grep "$gene" affy.txt | cut -d ' ' -f"$i" | sort -n | tail -1`
    #echo average columna "$i"= `grep "$gene" affy.txt | cut -d ' ' -f"$i" | awk '{sum+=$1} END {print sum/NR}'`

    #shift
    #done
#fi
4

0 回答 0