- 论坛徽章:
- 3
|
有这样格式的文本.
cj.txt我想用shell统计wuli,huaxue一共每科多少人并且找出其中多少人小于60.
最后得 ...
lordroc 发表于 2011-12-15 16:52 ![]()
a 95 wuli
b 54 wuli
c 84 huaxue
d 44 huaxue
复制代码我想用shell统计wuli,huaxue一共每科多少人并且找出其中多少人小于60.
最后得出的数字应该是
course total fail
wuli 2 1
huaxue 2 1
course=;cat urfile | sort -k3 | { echo course total fail;
while read A B C;do
if [ "$C" != "$course" ];then
if [ x"$course" != x ];then
echo $course $total $fail
fi
course=$C
total=1
if [ $B -lt 60 ];then
fail=1
else
fail=0
fi
else
let total++
if [ $B -lt 60 ];then
let fail++
fi
fi
done;
} |
|