brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Mask the numbers in logs and uniq -c finds the message that repeats most

Logs
~/tips/tip-logs-group-repeated-messages

sed -E 's/[0-9]+/N/g' app.log | sort | uniq -c | sort -rn | head -n 15

Collapse near identical lines to see which message dominates a file.

Ten thousand lines that differ only by an ID or a port number look like ten thousand problems. Usually there are a handful.

Replace every number with a placeholder, then count identical lines:

sed -E 's/[0-9]+/N/g' app.log | sort | uniq -c | sort -rn | head -n 15

The top of the output is the most frequent message shape with its count. A line like err id N from N.N.N.N now stands for all its variations.

Timestamps at the start become N too, which is what you want here. If each line begins with a hostname or a long random token, cut that part first:

cut -d' ' -f4- app.log | sed -E 's/[0-9]+/N/g' | sort | uniq -c | sort -rn | head

Adjust the field number to your format. For hex request IDs, add a second expression:

sed -E 's/[0-9a-f]{8,}/ID/g; s/[0-9]+/N/g' app.log | sort | uniq -c | sort -rn | head

I run this first on a log I have never seen. It shows what is normal noise there, and the rare lines at the bottom (tail instead of head) are often the interesting ones.

Masking throws information away. Two errors that differ only in a status code, say 404 and 500, merge into one line. Look at some original lines before you draw conclusions from a count.

Further reading: sed manual, uniq invocation

More Logs tips rotate 4 sort -m app.log worker.log | less awk '$1 >= "2026-11-30T02:00" && $1 < "2026-11-30T03:00"' app.log rotate 14 logger: All Logs tips (9) All topics

Link