Chinaunix首页 | 论坛 | 博客
  • 博客访问: 423258
  • 博文数量: 158
  • 博客积分: 1855
  • 博客等级: 上尉
  • 技术积分: 1888
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-18 14:19
文章分类

全部博文(158)

文章存档

2013年(4)

2012年(16)

2011年(10)

2010年(40)

2009年(61)

2008年(33)

分类:

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"]++
 }
}

阅读(1306) | 评论(0) | 转发(0) |
0

上一篇:grep awk

下一篇:linux+c

给主人留下些什么吧!~~