Stop manually counting log hits with ugly grep pipes
Text Processing (Grep/Sed/Awk)
Stop manually counting log hits with ugly grep pipes
🧩 The Challenge
Dealing with a massive access.log while trying to find out which IP is hammering your API is a total headache when you’re just chaining pipes and praying for the output to make sense. Half the time I end up with a mess of text that tells me nothing about the actual distribution of those requests.
💡 The Fix
Use awk to do the counting for you on the fly. It saves you from having to sort, count, and re-sort your logs manually every single time someone hits your endpoint too hard.
awk '{print $1}' access.log | sort | uniq -c | sort -nr | head -n 10
⚙️ Why It Works
By grabbing the first column and piping it through the sort and uniq utilities, you’re letting the OS build a frequency map of your log file before showing you the top offenders. Sorting it numerically in reverse order puts the biggest talkers right at the top where you need them.
🚀 Pro-Tip: Stick this into a shell alias if you’re constantly debugging traffic spikes.
Linux Tips & Tricks | © ngelinux.com | 8/30/2026
