Interview Prep/Shell Scripting/Text processing: grep, sed, awk, cut, sort, uniq

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.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Text processing: grep, sed, awk, cut, sort, uniq