From 8b8d451b285f2dd83f21c1b4382806fd36657cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Sat, 31 Oct 2020 07:56:56 +0200 Subject: [PATCH] add stats.awk --- III/Bautrenas/stats.awk | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 III/Bautrenas/stats.awk diff --git a/III/Bautrenas/stats.awk b/III/Bautrenas/stats.awk new file mode 100755 index 0000000..62da007 --- /dev/null +++ b/III/Bautrenas/stats.awk @@ -0,0 +1,28 @@ +#!/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. +/^\\partone\{$/ { idx=1; } +/^\\parttwo\{$/ { idx=2; } +/^\\partthree\{$/ { idx=3; } +/^\\partfour\{$/ { idx=4; } + +# 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]); + printf("number of characters in part4: %d\n", part[3]); +}