通过shell的while read line对一个文件中的考试分数进行人员分组,并记录分数
[root@ecs-18b3 ~]# cat split.sh
#!/bin/bash
while read line
do
name=`echo ${line}|awk '{print $1}'`
score=`echo ${line}|awk '{print $2}'`
if [ ${score} -gt 90 ];then
echo -e "${name} is S组"
echo -e "${line}" >> S组.txt
elif [ ${score} -gt 80 ];then
echo -e "${name} is A组"
echo -e "${line}" >> A组.txt
elif [ ${score} -gt 60 ];then
echo -e "${name} is B组"
echo -e "${line}" >> B组.txt
else
echo -e "${name} is C组"
echo -e "${line}" >> C组.txt
fi
done < /tmp/score.txt
[root@ecs-18b3 ~]# cat /tmp/score.txt
xiaoming 100
xiaohua 79
xiaohu 89
xiaoxue 99
xiaobai 40