O Awk fará isso:
awk '
BEGIN {
priority["ok"] = 10
priority["critical"] = 20
}
/^$/ {next}
/^checking/ {var = $NF}
{
if (priority[status[var]] < priority[$NF])
status[var] = $NF
if ($NF == "critical")
crit[var ":" $4] = 1
}
END {
for (var in status)
print var, status[var]
for (c in crit) {
split(c, ary, /:/)
printf("critical at %s for %s\n", ary[2], ary[1])
}
}
'
saídas
$var ok
$var2 ok
$var3 critical
critical at results3 for $var3