28 lines
935 B
Bash
Executable File
28 lines
935 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# normalize-noise-patterns.sh
|
|
#
|
|
# Read a log-noise.patterns file and emit a normalized stream of patterns
|
|
# that is safe to feed into `grep -Eaif`.
|
|
#
|
|
# Behaviour:
|
|
# - Lines starting with `#` (after optional leading whitespace) are dropped.
|
|
# - Empty / whitespace-only lines are dropped.
|
|
# - Leading and trailing whitespace is trimmed from each pattern.
|
|
# - Patterns that become empty after trimming are dropped.
|
|
#
|
|
# Why this exists:
|
|
# A single empty / whitespace-only line in the input file would make
|
|
# `grep -Eaif` match every input line, silently wiping the entire log
|
|
# highlights signal. Always pipe patterns through this normalizer first.
|
|
#
|
|
# Usage:
|
|
# normalize-noise-patterns.sh <file>
|
|
# cat patterns | normalize-noise-patterns.sh
|
|
set -euo pipefail
|
|
|
|
src="${1:-/dev/stdin}"
|
|
|
|
grep -Ev '^[[:space:]]*(#|$)' "$src" \
|
|
| sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//' \
|
|
| grep -v '^$' || true
|