The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-24-2008
shary shary is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 61
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
  #2 (permalink)  
Old 03-24-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,294
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
  #3 (permalink)  
Old 03-24-2008
naree naree is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 81
this will help u

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

Regards
Naree
  #4 (permalink)  
Old 03-25-2008
shary shary is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 61
Hi can you please explain that what does this command do
sort -nr +1. I am familiar with sort but what is -nr +1
  #5 (permalink)  
Old 03-25-2008
naree naree is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 81
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0