Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2003
    Posts
    2

    Unhappy Unanswered: Simple bourne shell question!!

    Hi, I am a newer for Bourne shell, I have a log file for a unix system, it some thing like:
    35.75.253.207 - - [17/Aug/2003:12:42:37 +1000] "GET /products/orgonizer/title.png HTTP/1.1" 200 1555 "-" "Mozilla 1.4"
    Now I want to list 10 most requested files in the log in a descending order, it something like
    157 /index.html
    129 /title.gif
    ...
    How should I count the duplicate file and display the number of requested in front of the file requested, like above, is there command avaliable to achieve that? I just know sort -nr is displaying the above in a descending order.
    Thanks for help

  2. #2
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    Use 'uniq' with the -c option.

    uniq -c yourFile

    Pipe into sort if you want to order it...

    uniq -c yourFile | sort -r

    Pipe into head if you only want n lines...

    uniq -c yourFile | sort -r | head -n # where n is the number of lines

    If for example the 10th and 11th lines had the same count and you wanted to return both, you would have to do something a little more sophisticated...

    uniq -c yourFile |
    sort -r |
    awk -v numRows=10 'NR>numRows && $1<lastCount {exit}{print; lastCount=$1}'


    HTH
    Last edited by Damian Ibbotson; 09-08-03 at 06:36.

  3. #3
    Join Date
    Sep 2003
    Posts
    2

    Wink hi

    Thanks, that is pretty helpful!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •