If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Simple bourne shell question!!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-08-03, 01:53
pnxi pnxi is offline
Registered User
 
Join Date: Sep 2003
Posts: 2
Unhappy 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
Reply With Quote
  #2 (permalink)  
Old 09-08-03, 05:17
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
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 05:36.
Reply With Quote
  #3 (permalink)  
Old 09-08-03, 21:36
pnxi pnxi is offline
Registered User
 
Join Date: Sep 2003
Posts: 2
Wink hi

Thanks, that is pretty helpful!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On