Nothing matched is an answer, not a failure — cheat sheet
bash, logging-journald
grep pattern file # 0 matched · 1 no match · 2 error
awk '/pattern/ { … }' file # 0 whether or not anything matched; non-zero if it cannot read
set -o pipefail # a pipeline's status = its last non-zero status
if grep -q pattern file; then … # a status being tested does not trigger set -e
sort | uniq -c | sort -k1,1nr -k2,2 # count occurrences, most frequent first, ties by name
awk '{ print $1, $2; n += $1 } END { print "total", n + 0 }'
[ -r "$LOG" ] || { echo "cannot read $LOG" >&2; exit 1; }
tmp=$(mktemp "$REPORT.XXXXXX"); trap 'rm -f -- "$tmp"' EXIT
… > "$tmp" && mv -f -- "$tmp" "$REPORT"
systemctl show unit -p Result -p ExecMainStatus
journalctl -u unit -b -o cat