shell script to sort the 5th column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script to sort the 5th column
# 1  
Old 06-16-2010
shell script to sort the 5th column

hi folks, I have this data in a data.txt file and i want to sort the 5th column and in descending order:
Code:
 Jun 15  119.167.247.40  =  23  Jun 15  119.167.247.40  =  3  Jun 15  208.115.46.125  =  12  Jun 15  208.115.46.125  =  6  Jun 15  210.51.10.160  =  20

I want this sample output:
Code:
   Jun 15  119.167.247.40  =  23  Jun 15  210.51.10.160  =  20  Jun 15  208.115.46.125  =  12  Jun 15  208.115.46.125  =  6  Jun 15  119.167.247.40  =  3

Thanks for your help..

Last edited by vgersh99; 06-16-2010 at 07:19 AM.. Reason: wrong presentation alignment
# 2  
Old 06-16-2010
Try:
Code:
xargs -n5 < data.txt | sort -k5rn | xargs

# 3  
Old 06-16-2010
Thanks Scrutinizer,

I got a new problem..
seems not easy to do alignment now when posting with codes or html.

regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to call and sort awk script and output

I'm trying to create a shell script that takes a awk script that I wrote and a filename as an argument. I was able to get that done but I'm having trouble figuring out how to keep the header of the output at the top but sort the rest of the rows alphabetically. This is what I have now but it is... (1 Reply)
Discussion started by: Eric7giants
1 Replies

2. Shell Programming and Scripting

Use sort to sort numerical column

How to sort the following output based on lowest to highest BE? The following sort does not work. $ sort -t. -k1,1n -k2,2n bfd.txt BE31.116 0s 0s DOWN DAMP BE31.116 0s 0s DOWN DAMP BE31.117 0s 0s ... (7 Replies)
Discussion started by: sand1234
7 Replies

3. UNIX for Beginners Questions & Answers

How to insert data into black column( Secound Column ) in excel (.XLSX) file using shell script?

Source Code of the original script is down below please run the script and try to solve this problem this is my data and I want it column wise 2019-03-20 13:00:00:000 2019-03-20 15:00:00:000 1 Operating System LAB 0 1 1 1 1 1 1 1 1 1 0 1 (5 Replies)
Discussion started by: Shubham1182
5 Replies

4. Shell Programming and Scripting

Need awk or Shell script to compare Column-1 of two different CSV files and print if column-1 matche

Example: I have files in below format file 1: zxc,133,joe@example.com cst,222,xyz@example1.com File 2 Contains: hxd hcd jws zxc cst File 1 has 50000 lines and file 2 has around 30000 lines : Expected Output has to be : hxd hcd jws (5 Replies)
Discussion started by: TestPractice
5 Replies

5. UNIX for Beginners Questions & Answers

Search spaces in 5th column in large file

i have a file having 5 columns with more than million records. And i want to search using UNIX command to find if there are any spaces in 5th column. any please help. (1 Reply)
Discussion started by: sivakumar.p
1 Replies

6. Shell Programming and Scripting

Calculate 5th percentile based on another column

I would like to have some help in calculating 5th percentile value of column 2 for each site, the input is like below:site val1 val2 002 10 25.3 002 20 25.3 002 30 25.3 002 40 20 002 50 20 002 60 20 002 70 20 002 80 30 002 90 30 002 100 30 002 120 30 003 20 30.3 003 20 30.3 003 30 20... (2 Replies)
Discussion started by: wuhuai
2 Replies

7. Linux

Filter a .CSV file based on the 5th column values

I have a .CSV file with the below format: "column 1","column 2","column 3","column 4","column 5","column 6","column 7","column 8","column 9","column 10 "12310","42324564756","a simple string with a , comma","string with or, without commas","string 1","USD","12","70%","08/01/2013",""... (2 Replies)
Discussion started by: dhruuv369
2 Replies

8. Shell Programming and Scripting

Total of 5th column using awk or any other utility in UNIX??

Hi I have this file which contains Al,AADESH,id1_0,23,2013-01-28,2,2 Al,AADESH,id1_0,23,2013-01-29,4,4 Al,AADESH,id1_0,23,2013-01-30,2,1 Al,AADESH,id1_0,31,2013-01-29,1,1 Al,AESH,id1_0,31,2013-01-31,2,2 Al,AESH,id2_2,23,2013-01-29,1,1 Al,AESH,id2_2,31,2013-01-31,1,1 ... (5 Replies)
Discussion started by: nikhil jain
5 Replies

9. Shell Programming and Scripting

Question about sort specific column and print other column at the same time !

Hi, This is my input file: ali 5 usa abc abu 4 uk bca alan 6 brazil bac pinky 10 utah sdc My desired output: pinky 10 utah sdc alan 6 brazil bac ali 5 usa abc abu 4 uk bca Based on the column two, I want to do the descending order and print out other related column at the... (3 Replies)
Discussion started by: patrick87
3 Replies

10. Shell Programming and Scripting

Can we use 'tr' command to print 5th column of output of 'ls -l'

Hi All, I know awk command can do it, but can we use tr command to print 5th column of out put 'ls -l' command???? Regards, Nidhi... (4 Replies)
Discussion started by: Nidhi2177
4 Replies
Login or Register to Ask a Question