Stop manually scrubbing your logs for field-specific values

Text Processing (Grep/Sed/Awk)

Stop manually scrubbing your logs for field-specific values

🧩 The Challenge

You are staring at a massive server log trying to pull out every unique source IP address that triggered a 404 error, and you’re probably tempted to just open it in an editor and scroll. Nobody has time for that, and you’ll definitely miss something.

💡 The Fix

Use awk to grab just the column you care about and pipe it into sort and uniq to get a clean, sorted list of unique entries. It saves you from eye-straining manual cleanup.

awk '$9 == 404 {print $1}' access.log | sort | uniq -c | sort -nr

⚙️ Why It Works

By telling awk to only look at the ninth column for your target error code, you instantly filter out the noise before feeding the result into the standard unix sorting pipeline.

🚀 Pro-Tip: Add sort -nr at the end if you want to see which IPs are hitting that error the most, not just which ones they are.

Linux Tips & Tricks | © ngelinux.com | 9/24/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted