Count all http response status codes in a web application log files on linux

Azure Administrator AZ-104 Exam Questions and Answers Dumps

You can translate the content of this page by selecting a language in the select box.

AI Unraveled: Demystifying Frequently Asked Questions on Artificial Intelligence

Count all http response status codes in a web application log files on linux

Here is one way to count all the HTTP response status codes in a web application log file on Linux:

Achieve AWS Solutions Architect Associate Certification with Confidence: Master SAA Exam with the Latest Practice Tests and Quizzes illustrated

  1. Open the log file using the cat command:
cat log_file
  1. Use the grep command to search for lines that contain an HTTP status code:
cat log_file | grep -Eo 'HTTP/[0-9\.]+ [0-9]+'

This will output all the lines in the log file that contain an HTTP status code.

  1. Use the awk command to extract the status code from each line:
cat log_file | grep -Eo 'HTTP/[0-9\.]+ [0-9]+' | awk '{print $2}'

This will output a list of all the status codes in the log file.

  1. Use the sort and uniq commands to count the number of occurrences of each status code:
cat log_file | grep -Eo 'HTTP/[0-9\.]+ [0-9]+' | awk '{print $2}' | sort | uniq -c

1- Sample Log file:

Given the log file below, we want to know all http response status code and sort them from the highest amount of response code to the lowest.


2- Use this command below to Count all http response status codes in a web application log files on linux:




awk '{print $9}' sample_log.log | sort | uniq -c | sort -rn

3- Output

Count Each unique Response Status Code from Web App log file

Learn more about http response status code here

error: Content is protected !!