stud/III/Bautrenas/task1/stats.awk

29 lines
928 B
Awk
Raw Normal View History

2020-10-31 07:56:56 +02:00
#!/usr/bin/awk -f
# Beginning of a section ("part") starts with:
# \partNUMBER{
# where NUMBER := (one | two | three | four). The ^ and $ signify line's
# beginning and end marks. When section begins, assign `idx` to its number.
2020-10-31 22:13:55 +02:00
/^\\partone\{$/ { idx=1; }
/^\\parttwo\{$/ { idx=2; }
2020-10-31 07:56:56 +02:00
/^\\partthree\{$/ { idx=3; }
2020-10-31 22:13:55 +02:00
/^\\partfour\{$/ { idx=4; }
2020-10-31 07:56:56 +02:00
# Section ends with "}" as a sole character in the line.
/^\}$/ { idx=0; }
# If idx != 0 (we are in part1,2,3 or 4), increase part's counter by the number
# of characters in the line.
idx != 0 {
part[idx] += length($0);
}
# End of the script: we have part[idx], where idx := [1,4], and the
# value is the number of characters.
END {
printf("number of characters in part1: %d\n", part[1]);
printf("number of characters in part2: %d\n", part[2]);
printf("number of characters in part3: %d\n", part[3]);
2020-10-31 22:13:55 +02:00
printf("number of characters in part4: %d\n", part[4]);
2020-10-31 07:56:56 +02:00
}