-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp5.awk
30 lines (30 loc) · 873 Bytes
/
p5.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#Usage awk -f p5.awk [fnames]
#print a histogram for number of "a" grades, "b" grades, etc
#assume record is: LName SID Mark
#only include records that have a sid in field 2
BEGIN {print "Histogram of marks:"}
$2~/[0-9]+/ { #~ is "contains", "+" is one-or-more of previous
#(remember "*" is zero-or-more)
t=t+1
if ($3>=80) ++a
if ($3>=70&&$3<80) ++b
if ($3>=60&&$3<70) ++c
if ($3>=50&&$3<60) ++d
if ($3<50) ++f
}
END {
#need printf statements because print always puts a newline
#every time it is executed. So instead of AAAA would get each on
#a new line within the for loop
for (i=1;i<=a;i++) printf "%s", "A"
printf "\n"
for (i=1;i<=b;i++) printf "%s", "B"
printf "\n"
for (i=1;i<=c;i++) printf "%s", "C"
printf "\n"
for (i=1;i<=d;i++) printf "%s", "D"
printf "\n"
for (i=1;i<=f;i++) printf "%s", "F"
printf "\n"
print "Total records processed:", t
}