#!/usr/bin/env bash set -euo pipefail lcov_path="${1:-}" if [[ -z "${lcov_path}" || ! -f "${lcov_path}" ]]; then echo "usage: $0 " >&2 exit 2 fi # lcov format includes per-file LF (lines found) and LH (lines hit). Sum those. awk ' /^LF:/ { lf += substr($0, 4) } /^LH:/ { lh += substr($0, 4) } END { if (lf == 0) { printf("lines: 0/0 (0.00%%)\n") exit 0 } pct = (lh * 100.0) / lf printf("lines: %d/%d (%.2f%%)\n", lh, lf, pct) } ' "${lcov_path}"