全部博文(158)
分类:
2008-09-23 14:45:01
[root@server0 b]# cat grade
35#senior
45#junior
65#junior
69#senior
69#junior
45#senior
72#junior
78#senior
80#junior
85#junior
90#senior
91#junior
96#junior
[root@server0 b]# ./awk_array.sh grade
the score 0-60 has 3 students
the score 70-80 has 2 students
the score 90-100 has 3 students
the score 60-70 has 3 students
the score 80-90 has 2 students
the class has 5 senior students
the class has 8 junior students
[root@server0 b]#
[root@server0 b]# cat awk_array.sh
#!/bin/awk -f
#awk_array.sh
BEGIN{
FS="#" #-F "#"
score["0-60"]=0
score["60-70"]=0
score["70-80"]=0
score["80-90"]=0
score["90-100"]=0
student["junior"]=0
student["senior"]=0
}
{
{if($1<60)
score["0-60"]++
}
{if($1<70&&$1>=60)
score["60-70"]++
}
{if($1<80&&$1>=70)
score["70-80"]++
}
{if($1<90&&$1>=80)
score["80-90"]++
}
{if($1<=100&&$1>=90)
score["90-100"]++
}
}