#!/bin/sh # A report built the way a deployment script builds one: read a log line # by line, count it by level and by hour, print the totals. case, read, # arithmetic and printf, which is the shape of most real scripts. awk 'BEGIN { for (i = 0; i < 20000; i++) { lvl = (i % 7 == 0) ? "ERROR" : (i % 3 == 0) ? "WARN" : "INFO" printf "%02d:%02d:%02d %s job%d step%d\n", i % 24, i % 60, (i * 7) % 60, lvl, i % 40, i % 12 } }' >bench.tmp errors=0 warns=0 night=0 while read -r stamp level rest; do case $level in ERROR) errors=$((errors + 1)) ;; WARN) warns=$((warns + 1)) ;; esac hour=${stamp%%:*} case $hour in [0-7]?) night=$((night + 1)) ;; esac done