|
楼主 |
发表于 2004-12-3 21:58:02
|
显示全部楼层
我处理文件的awk脚本是:
BEGIN { FS=":"
print "\t\t\t***CAMPAIGN 1998 CONTRIBUTIONS***"
print "---------------------------------------------------------------------------------"
print "NAME\t\t\tPHONE\t Jan | Feb | Mar | Total Donated"
print "---------------------------------------------------------------------------------"
}
{
gsub(/\$/,"")
$6=$3+$4+$5
printf("%-20s%-16s%-10.2f%.2f\t%.2f\t %10.2f\n",$1,$2,$3,$4,$5,$6)
}
{total+=$6}
{
for(i=3;i<NF-1;i++) {
dona[i-1]=$i
if(dona[0]<dona[i-1]) dona[0]=dona[i-1]
if(dona[1]==0) dona[1]=dona[2]
if(dona[1]>dona[i-1]) dona[1]=dona[i-1];
}
}
{
if(max<$6) {
name=$1;
max=$6;
}
if($6>500) {
j++;
group[j]=$1"--";
telephone[j]=$2;
}
}
END {
print "---------------------------------------------------------------------------------"
print "\t\t\t\t SUMMARY"
print "---------------------------------------------------------------------------------"
printf("The campaign received a total of $%.2f for this quarter.\n",total)
printf("The average donation for the %d contributors was $%.2f.\n",NR,total/NR)
printf("The highest contribution was $%.2f.\n",dona[0])
printf("The lowest contribution was $%.2f.\n",dona[1])
split(name,nick," ")
printf("The highest total contribution was $%.2f made by %s\n",max,name)
printf("\t\t\t\t ***THANKS %s ***\n",nick[1])
print "The following people donated over $500 to the campaign!\nThey are eligible for the quarterly drawing !!\nListed are their names ( sorted by last names ) and phone numbers:"
group[j+1]="\tThanks to all of you for your continued support!!"
for(i=1;i<=j+1;i++) print "\t"grouptelephone | "sort +1 -2"
} |
|