stud

study spacejunk
Log | Files | Refs | LICENSE

commit 8b8d451b285f2dd83f21c1b4382806fd36657cbf (tree)
parent 078a0433af51d340cf94395bed6570545a82f2dc
Author: Motiejus Jakštys <motiejus@uber.com>
Date:   Sat, 31 Oct 2020 07:56:56 +0200

add stats.awk

Diffstat:
AIII/Bautrenas/stats.awk | 28++++++++++++++++++++++++++++
1 file changed, 28 insertions(+), 0 deletions(-)

diff --git a/III/Bautrenas/stats.awk 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]); +}