need top 3 numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need top 3 numbers
# 1  
Old 03-24-2008
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  
Old 03-24-2008
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  
Old 03-24-2008
this will help u

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

Regards
Naree
# 4  
Old 03-25-2008
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  
Old 03-25-2008
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Decimal numbers and letters in the same collums: round numbers

Hi! I found and then adapt the code for my pipeline... awk -F"," -vOFS="," '{printf "%0.2f %0.f\n",$2,$4}' xxx > yyy I add -F"," -vOFS="," (for input and output as csv file) and I change the columns and the number of decimal... It works but I have also some problems... here my columns ... (7 Replies)
Discussion started by: echo manolis
7 Replies

2. Shell Programming and Scripting

[Solved] Help on extracting the numbers out of top command

Hi guys, Any easy way to generate a CSV file that contains only the numbers out of the following lines? load averages: 15.09, 12.89, 11.76 03:39:22 999 processes: 854 sleeping, 2 running, 122 zombie, 5 stopped, 16 on cpu Memory: 32G real, 17G free, 18G swap in use, 15G swap free ... (6 Replies)
Discussion started by: ejianu
6 Replies

3. UNIX for Dummies Questions & Answers

Print numbers and associated text belonging to an interval of numbers

##### (0 Replies)
Discussion started by: lucasvs
0 Replies

4. Shell Programming and Scripting

the smallest number from 90% of highest numbers from all numbers in file

Hello All, I am having problem to find what is the smallest number from 90% of highest numbers from all numbers in file. I am having file with thousands of lines and hundreds of columns. I am familiar mainly with bash but I am open to whatever suggestion witch will lead to the solutions. If I... (11 Replies)
Discussion started by: Apfik
11 Replies

5. UNIX for Dummies Questions & Answers

Replace US numbers with European numbers

hey, I have a file with numbers in US notation (1,000,000.00) as well as european notation (1.000.000,00) i want all the numbers to be in european notation. the numbers are in a text file, so to prevent that the regex also changes the commas in a sentence/text i thought of: sed 's/,/\./'... (2 Replies)
Discussion started by: FOBoy
2 Replies

6. AIX

Need a list of top 10 CPU using processes (also top 10 memory hogs, separately)

Okay, I am trying to come up with a multi-platform script to report top ten CPU and memory hog processes, which will be run by our enterprise monitoring application as an auto-action item when the CPU and Memory utilization gets reported as higher than a certain threshold I use top on other... (5 Replies)
Discussion started by: thenomad
5 Replies

7. AIX

Top command in AIX 4.2 (no topas, no nmon, no top)?

Is there a 'top' command equivalent in AIX 4.2 ? I already checked and I do not see the following ones anywhere: top nmon topas (1 Reply)
Discussion started by: Browser_ice
1 Replies

8. Shell Programming and Scripting

read numbers from file and output which numbers belongs to which range

Howdy experts, We have some ranges of number which belongs to particual group as below. GroupNo StartRange EndRange Group0125 935300 935399 Group2006 935400 935476 937430 937459 Group0324 935477 935549 ... (6 Replies)
Discussion started by: thepurple
6 Replies

9. UNIX for Dummies Questions & Answers

seperating records with numbers from a set of numbers

I have two files one (numbers file)contains the numbers(approximately 30000) and the other file(record file) contains the records(approximately 40000)which may or may not contain the numbers from that file. I want to seperate the records which has the field 1=(any of the number from numbers... (15 Replies)
Discussion started by: Shiv@jad
15 Replies

10. UNIX for Dummies Questions & Answers

How Can I Have Top Display The Top 20 Processes??

how can i do that in a script withough havin the script halt at the section where the top command is located. am writign a script that will send me the out put of unx commands if the load average of a machine goes beyond the recommended number. top -n 20 i want to save this output to a file... (1 Reply)
Discussion started by: TRUEST
1 Replies
Login or Register to Ask a Question