FreeTstar

loving Freedom + + loving Linux

  • 首页
  • Archive
  • 关于
  • 杂七杂八
  • 留言板
Twitter Sina RSS

unix shell范例精解第七章课后习题《二》

发布于 2010年05月31日 由 freetstar
2 条评论发表评论
Mike Harrington:(510) 548-1278:250:100:175
Christian Dobbins:(408) 538-2358:155:90:201
Susan Dalsass:(206) 654-3279:250:60:50
Archie McNichol:(206) 548-1348:250:100:175
Jody Savage:(206) 548-1278:15:188:150
Guy Quigley:(916) 343-6410:250:100:175
Dan Savage:(406) 298-7744:450:300:275
Nancy McNeil:(510) 548-5258:250:80:75
John Goldenrod:(916) 348-4278:250:100:175
Chet Main:(510) 548-5258:50:95:135
Tom Savage:(408) 926-3456:250:168:200
Elizabeth Stachelin:(916) 440-1763:175:75:300

上面这个数据库的记录内容包括姓名,电话号码和最近3个月的竞选捐款数额 注:以上内容被写进chapter7这个文档

请编写一个能产生如下输出的nawk的脚本:
***FIRST QUARTERLY REPROT***
***CAMPAIGN  1998  CONTRIBUTIONS***
————————————————————————————–
NAME PHONE Jan  |   Feb   |  Mar    |  Total.Donated
————————————————————————————–
Mike       Harrington      (510) 548-1278    250.00    100.00     175.00      525.00
Christian     Dobbins     (408) 538-2358    155.00     90.00     201.00      446.00
Susan         Dalsass         (206) 654-3279    250.00     60.00      50.00      360.00
Archie       McNichol      (206) 548-1348    250.00    100.00     175.00      525.00
Jody           Savage           (206) 548-1278     15.00    188.00     150.00      353.00
Guy           Quigley           (916) 343-6410    250.00    100.00     175.00      525.00
Dan            Savage          (406) 298-7744    450.00    300.00     275.00      1025.00
Nancy          McNeil        (510) 548-5258    250.00     80.00      75.00      405.00
John        Goldenrod      (916) 348-4278    250.00    100.00     175.00      525.00
Chet             Main            (510) 548-5258     50.00     95.00     135.00      280.00
Tom            Savage          (408) 926-3456    250.00    168.00     200.00      618.00
Elizabeth   Stachelin     (916) 440-1763    175.00     75.00     300.00      550.00
—————————————————————————————
SUMMARY
—————————————————————————————
THe campaign recevied a total of $6137.00 for this quaiter
The average donation for the 12 contributions was $511.42
The highest total contribution was 1025.00 made by Dan
***THANKS Dan ***
The following people donated over $500.00 to the campaign
They are eligible for the quarterly drawing
Listed are their names (sorted by last names) and phone numbers:
Mike Harrington– (510) 548-1278
Archie McNichol– (206) 548-1348
Guy Quigley– (916) 343-6410
Dan Savage– (406) 298-7744
John Goldenrod– (916) 348-4278
Tom Savage– (408) 926-3456
Elizabeth Stachelin– (916) 440-1763
Thanks to all of you for your continued support!!
我的脚本文件
cat nawk7.2.sc
BEGIN{
printf "\t\t\t     ***FIRST QUARTERLY REPROT***\t\t\t\n"
printf "\t\t\t   ***CAMPAIGN  1998  CONTRIBUTIONS***\t\t\t\n"
printf "————————————————————————————–\n"
printf "NAME\t\t\t    PHONE\t\tJan  |   Feb   |  Mar    |  Total.Donated\n"
printf "————————————————————————————–\n"
FS="[ :]"
}
#compute the max donation and donor's name
#print the donate status
#print the average
#put the record into the matrix
{
while(count<NR){count++;$8=$5+$6+$7;sum+=$8;if($8>max){max=$8;name=$1}}
printf "%-10s %10s    %s %s    %6.2f    %6.2f     %6.2f      %6.2f \n",$1,$2,$3,$4,$5,$6,$7,$5+$6+$7
average=int(sum/1200)*100
for(i=1;i<=4;i++)
{
if($8>500) matrix[NR,i] = $i
}
}
END{
printf "—————————————————————————————\n"
printf "\t\t\t\t\t\ SUMMARY \t\t\t\t\t\t\t\n"
printf "—————————————————————————————\n"
printf "THe campaign recevied a total of $%6.2f for this quaiter\n",sum
printf "The average donation for the 12 contributions was $%6.2f\n",sum/12
printf "The highest total contribution was %6.2f made by %s \n ", max,name
printf "                      ***THANKS %s ***         \n",name
printf "The following people donated over $%6.2f to the campaign\n",average
printf "They are eligible for the quarterly drawing \n"
printf "Listed are their names (sorted by last names) and phone numbers:\n"
for(i=1;i<=NR;i++)
{
for(j=1;j<=4;j++)
{
if(matrix[i,j]) printf " %s", matrix[i,j]
if(matrix[i,j] && j==2) printf "–"
if(matrix[i,j] && j==4) printf "\n"
}
}
printf "\t\t Thanks to all of you for your continued support!!\n"
}
格式控制比较麻烦- -!
分类:PROGRAM
读一初中生日志有感
Google Chrome 升级之后字体发虚问题解决办法

2 则回应给 “unix shell范例精解第七章课后习题《二》”

  1. delectate CHINA Mozilla Linux 说道:
    2010年05月31日 9:37 下午

    主题不错,就是背景重复,看起来过于繁乱,如果背景图设置透明度50%效果会更好

    上边那个google translate是wp默认的吗?还是

    [回复]

    admin CHINA Google Chrome Linux 回复:
    五月 31st, 2010 at 11:36 下午

    哈哈,估计你来这会我正在实验背景了,被我重复换了n的n次方次…

    那个是个插件,是这个主题自带的.我现在用的主题可定制性比较强,很多可选项,那个翻译的就是主题自带的

    [回复]

发表评论 取消回复

电子邮件地址不会被公开。 必填项已用 * 标注

*

*


疑问 开心 悲伤 邪恶 惊叹 微笑 脸红 笑 惊讶 惊奇 迷惑 酷 憨笑 生气 阴险 转眼球 眨眼 主意 箭头 中立 哭 大笑

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image

点击取消回复
第 1 页,共 1 页1
  • 欢迎订阅

  • Github

  • 近期评论

    • freetstar CHINA Mozilla Firefox Linux 发表在《留言板》
    • _Fly CHINA Google Chrome Linux 发表在《使用e4rat加速你的linux启动速度(ext4文件系统专用)》
    • walfred Mozilla Firefox Windows 发表在《留言板》
    • freetstar CHINA Mozilla Firefox Windows 发表在《用landslide创建html5 slide》
  • Spread Firefox Affiliate Button
  • 我的豆瓣

  • 链接表

    • 51开源社区
    • Adam's
    • delectate's blog
    • Don's
    • fl
    • ghostunix
    • Jasey Wang
    • Jerry's Blog
    • Moolight@Ericyue
    • OSMSG
    • panda
    • Pity is the Bomp
    • PT ubuntu
    • Tao Zhu
    • ubuntuhome
    • WOW!ubuntu
    • zhangzhfang
    • 丕字的blog
    • 傻东の学习笔记
    • 奶牛的blog
    • 孤风颠影
    • 弯柚博客
    • 熊猫党军委主席
    • 靖 轩
    • 马力哥
    • 黑孩儿
  • 我的支付宝

  • 功能

    • 登录
    • 文章 RSS
    • 评论 RSS
    • WordPress.org
© FreeTstar. WordPress 强力驱动 | Nest Theme by YChong