Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a PHP application that is generating large amounts of warnings and notices in the log file..

I'm fixing these one at a time.

I would like to be able to fix the most frequently occurring first in order to maximize the amount of effect my changes have on the size of the log file.

How can I use grep/sed/regex etc.find out which notices are most frequent?

I can't compare the whole line since the time stamp is at the beginning, but perhaps a listing/grouping/sorting of "on line ..."?

alt text

share|improve this question
up vote 8 down vote accepted

How about this?

grep 'on line' /var/log/httpd/error_log | cut -d' ' -f6- | sort | uniq -c | sort -nr


  1. Get the right lines from the logfile
  2. Chop the date off the front
  3. Sort them
  4. Aggregate and count the duplicates
  5. Sort by number of duplicates
share|improve this answer
exactly what I was looking for thanks – Edward Tanguay Aug 10 '09 at 8:35

I think this is more concise, so you really could avoid 'cut'.

  grep -o 'on line [[:digit:]]*' /var/log/nginx/error.log | sort | uniq -c | sort -nr
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.