The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
uniq command??? skyineyes UNIX for Dummies Questions & Answers 2 05-28-2008 03:27 AM
uniq options dhanamurthy Shell Programming and Scripting 0 05-08-2008 05:08 AM
Uniq using only the first field Digby UNIX for Dummies Questions & Answers 8 01-16-2008 02:25 AM
help on UniQ vishal_ranjan HP-UX 0 06-21-2007 07:33 AM
sort/uniq jimmyflip UNIX for Dummies Questions & Answers 3 10-17-2002 02:09 AM

Reply
 
LinkBack Thread Tools Display Modes
  #8 (permalink)  
Old 05-17-2008
Registered User
 

Join Date: May 2008
Posts: 53
ok that works perfectly thank you.

how do i sort this code so that the number of hits per page is sorted in descending order?

so the code which is this:
Code:
awk -F'[: ]' 'END {
fmt = "%-20s\t%s\t%s\n"
printf fmt, "Page:", "Hits:", "Unique Hits:"
for (p in h)
  printf fmt, p, h[p], u[p]
}
!_[$1,$2]++ { u[$1]++ }
{ h[$1]++ }' HITS
needs to be edited so that the output looks like this:
Code:
Page:                 Hits:  Unique Hits:
hits/blog.hits      	124	84
hits/mags.hits      	119	79
hits/dvds.hits      	48	35
hits/food.hits      	46	40
hits/news.hits      	42	40
hits/jobs.hits      	33	29
Reply With Quote
Forum Sponsor
  #9 (permalink)  
Old 05-17-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,094
Pipe to sort -k2rn. Maybe some hack to print the header separately.
Reply With Quote
  #10 (permalink)  
Old 05-17-2008
Registered User
 

Join Date: May 2008
Posts: 53
so where about does that go into the code? (sorry i am a bit of a beginner.)
Reply With Quote
  #11 (permalink)  
Old 05-17-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,094
Code:
awk -F'[: ]' 'END {
fmt = "%-20s\t%s\t%s\n"
printf fmt, "Page:", "Hits:", "Unique Hits:"
for (p in h)
  printf fmt, p, h[p], u[p]
}
!_[$1,$2]++ { u[$1]++ }
{ h[$1]++ }' HITS |
( IFS='' read header; echo "$header"; sort -k2rn )
The read takes one line off and prints it, leaving the rest as input to sort.
Reply With Quote
  #12 (permalink)  
Old 05-17-2008
Registered User
 

Join Date: May 2008
Posts: 53
Thank you very much.

How the hell do you guys learn all this sooo quickly. Its mental.
Reply With Quote
  #13 (permalink)  
Old 05-17-2008
Registered User
 

Join Date: Oct 2006
Location: Belgium
Posts: 171
Quote:
Originally Posted by radoulov View Post
Another one
(use nawk or /usr/xpg4/bin/awk on Solaris):

Code:
awk -F'[: ]' 'END {
fmt = "%-20s\t%s\t%s\n"
printf fmt, "Page:", "Hits", "Unique Hits"
for (p in h)
  printf fmt, p, h[p], u[p]
}
!_[$1,$2]++ { u[$1]++ }
{ h[$1]++ }' file
That's neat and terse! Exactly the way I like it! I should have thought to use a regex as FS.
Reply With Quote
  #14 (permalink)  
Old 05-17-2008
Registered User
 

Join Date: Mar 2008
Posts: 55
Thats why i like to say to say era is really a nice person and understand problem and reply the solution quickly.

Regards,
Bash
Reply With Quote
Google UNIX.COM
Reply

Tags
solaris

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0