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
How to add numbers email-lalit Shell Programming and Scripting 8 05-12-2008 03:34 PM
ksh and hex numbers JamesByars Shell Programming and Scripting 2 01-15-2008 11:36 AM
to count their numbers using awk cdfd123 Shell Programming and Scripting 3 10-15-2007 12:24 AM
How to add numbers? pnxi Shell Programming and Scripting 7 09-11-2003 03:25 AM
Add some numbers! TalkShowHost Shell Programming and Scripting 3 05-15-2002 09:28 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-24-2008
Registered User
 

Join Date: Jan 2007
Posts: 48
Stumble this Post!
need top 3 numbers

Hi Every one

I have a text file which is having a might be 100,000 record but i only need a maximum top 3 numbers and its phone number .
please see below the samle file

usa,asasas,ssss,asasasasas,9005451,10000,ikiikkk
uk,asasas,ssss,asasasasas,9005452,110000,ikiikkk
uae,asasas,ssss,asasasasas,9005453,20000,ikiikkk
china,asasas,ssss,asasasasas,9005454,10,ikiikkk
kuwait,asasas,ssss,asasasasas,9005455,100,ikiikkk
qatar,asasas,ssss,asasasasas,9005456,5000000,ikiikkk
bahrain,asasas,ssss,asasasasas,9005457,80,ikiikkk

I need the top three maximum charge vaue which is filed number 6.
it should give me the top 3 results like this.

9005456,5000000
9005452,110000
9005453,20000

PLEASE GIVE ME ANY COMMAND OR UNIX SHELL SCRIPT WHICH CAN HELP ME OUT TO CALCULATE THE TOP 3 NUMBERS OR EVEN I CAN APPLY THIS WITH 100 NUMBERS.
Regards
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-24-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,961
Stumble this Post!
You can achieve this with some basic commands.
Cut the 5th and the 6th columns, do a numeric sort and use head to print the first lines.

Regards
Reply With Quote
  #3 (permalink)  
Old 03-24-2008
Registered User
 

Join Date: Feb 2008
Posts: 77
Stumble this Post!
this will help u

cat filename | awk -F"," '{print $5 " " $6}' | sort -nr +1 | head -3

Regards
Naree
Reply With Quote
  #4 (permalink)  
Old 03-24-2008
Registered User
 

Join Date: Jan 2007
Posts: 48
Stumble this Post!
Hi can you please explain that what does this command do
sort -nr +1. I am familiar with sort but what is -nr +1
Reply With Quote
  #5 (permalink)  
Old 03-24-2008
Registered User
 

Join Date: Feb 2008
Posts: 77
Stumble this Post!
Hi

sort -nr +1

-n ---> is number sort
-r ---> is in reverse order
+1 becoz it leave first coloum in output and sort second one ..

Regards

Naree
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:12 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