How do you extract the top 10 client IPs from an Nginx access log?
BeginnerConceptText processing: grep, sed, awk, cut, sort, uniq
Answer
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -n 10
Explain each stage: awk extracts field 1 (client IP in the combined format), sort groups identical IPs, uniq -c counts, sort -rn orders by count descending, head keeps 10. Behind a load balancer, field 1 is the LB's IP; read the X-Forwarded-For field from your log format instead.
More on Text processing: grep, sed, awk, cut, sort, uniq
What are the most useful `grep` flags?BeginnerWhat is the difference between basic, extended and Perl regular expressions in grep?IntermediateWhat are the core `sed` commands you use in automation?BeginnerWhy does `sed -i` behave differently on macOS and Linux?IntermediateHow do you use variables inside a `sed` expression safely?AdvancedWhat is the structure of an `awk` program?Beginner