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.

Ace the AWS Cloud Practitioner Certification CCP CLF-C02 Exam: Prepare and Ace the AWS Cloud Practitioner Certification CCP CLF-C02

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:

  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.


Ace the AWS Solutions Architect Associates SAA-C03 Certification Exam : Quizzes, Flashcards, Practice Exams, Cheat Sheets, I passed SAA Testimonials, Tips and Tricks to ace the SAA-C03 exam
  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:


AI Unraveled: Demystifying Frequently Asked Questions on Artificial Intelligence (OpenAI, ChatGPT, Google Bard, Generative AI, Discriminative AI, xAI, LLMs, GPUs, Machine Learning, NLP, AI Podcast)




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

3- Output

If you are looking for an all-in-one solution to help you prepare for the AWS Cloud Practitioner Certification Exam, look no further than this AWS Cloud Practitioner CCP CLFC01 book

Count Each unique Response Status Code from Web App log file

Learn more about http response status code here

error: Content is protected !!