How to quickly parse an Apache logfile with AWK

awk '{print $9}' apache_access.log | sort | uniq -c | sort -r | head -n 25  

The above command line is a pipeline of several commands…

sort: This takes the output of the previous command (the list of HTTP status codes) and sorts them in ascending order.

uniq -c : filters out repeated lines that are adjacent, and -c adds a count of how many times each line occurred. Since the input is sorted, this counts how many times each time a specific instance of a code appears in the log.

sort -r : This sorts the output of the previous command (the count of each status code) in reverse order (i.e., descending order).

head -n 25 : displays the first 25 lines of the sorted output. This shows the top 25 HTTP status codes by frequency in the log file.