UNIX sort command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers UNIX sort command
# 1  
Old 04-27-2010
UNIX sort command

Need some help with the sort command. I have a large file which needs sorted on the third field separated by : and within the third field, I need it sorted by second field or everything after the . An example of my file is here and for example, the first line I need :ROUTER2.SFLDMI: sorted on the SFLDMI.
Code:
SFLDMI5_S3P14:1-255:ROUTER2.SFLDMI:GLOBAL.NET:11/0:155000:SOUTHFIELD:
SFLDMI6_S4P14:1-255:ROUTER3.SFLDMI:GLOBAL.NET:8/0:155000:SOUTHFIELD:
SFLDMI7_S3P1:1-255:ROUTER4.SFLDMI:GLOBAL.NET:10/0:155000:SOUTHFIELD:
13.OBBB.000330.SUV:1-255:ROUTER3.WOTNOH:GLOBAL.NET:8/0:155000:WORTHINGTON:
01.OBBB.100081:1-255:CISCO1.ABLNTX:GLOBAL.NET:1/0:155000:ABILENE:
45.OBBB.001990:1-255:CISCO2.ABLNTX:GLOBAL.NET:1/0:155000:ABILENE:
00.SFLD.MISEBA5_S5P1:1-255:ROUTER12.SFLDMI:GLOBAL.NET:10/0:155000:Southfield:
00.SFLD.MISEBA5_S4P14:1-255:ROUTER13.SFLDMI:GLOBAL.NET:11/0:155000:Southfield:
00.WOTN.OHATBB3_S11P3:1-255:ROUTER2.WOTNOH:GLOBAL.NET:11/0:155000:Worthington:
22.OBBB.001066:1-255:CISCO1.BKFDCA:GLOBAL.NET:1/0:155000:Bakersfield:
22.OBBB.001177:1-255:CISCO2.BKFDCA:GLOBAL.NET:1/1:155000:Bakersfield:

# 2  
Old 04-27-2010
How about:
Code:
awk -F: '{split($3,F,".");print F[2],F[1],$0}' infile | sort | sed 's/.* //'

# 3  
Old 04-27-2010
Thanks Scrutinizer, works great!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX sort

Hi I have below pattern A: Apple 2 B:Bolls 4 total_count = 6 A: pens 4 B:Bags 4 total count = 8 A: pens 4 B:Bags 4 A: cells 6 A: jobs 6 Output I need : A: Apple 2 B:Bolls 4 total_count = 6 A: pens 4 B:Bags 4 total count = 8 A: cells 6 A: jobs 6 ... (7 Replies)
Discussion started by: pkkanduk
7 Replies

2. Linux

sort command in centos unix

Iam working in centos linux operating system. Consider the following file by name emp 1008 Vijay 40 1009 Rekha 34 1010 Shreyas 40 1011 Sanjay 40 sort command is not working. I gave sort emp The command is not working Can somebody send the options under centos linux (1 Reply)
Discussion started by: jpachar
1 Replies

3. Shell Programming and Scripting

Help to sort out... Possible use of sort command

I have an input like 4.3.6.66 4.3.6.67 4.3.6.70 4.3.6.25 4.3.6.15 4.3.6.54 4.3.6.44 4.3.6.34 4.3.6.24 4.3.6.14 4.3.6.53 4.3.6.43 4.3.6.49 4.3.6.33 4.3.6.52 4.3.6.19 4.3.6.58 4.3.6.42 (5 Replies)
Discussion started by: dnam9917
5 Replies

4. UNIX for Dummies Questions & Answers

New to Unix command line and have a question about the "sort" command

I am going through the Unix Made Easy second edition book by John Muster. So far it's been very informative and I can tell it may be a bit out of date. In one of the exercises it talks about the "sort" command and using it to sort column's of data etc. The "sort" command has changed a bit and... (1 Reply)
Discussion started by: budfoxcat
1 Replies

5. UNIX for Advanced & Expert Users

Sort command using unix

Hello, I have a file with 'tab' separated columns. The first column of the file contains integer values. Now I want to sort the first column in ascending order. Can someone help me on this... thanks in advance (1 Reply)
Discussion started by: koneru_18
1 Replies

6. Shell Programming and Scripting

Is it Possible to sort a list of hexadecimal numbers using "sort" command?

Hello Everybody :) !!!. i have question in mind, is it possible to sort a list of hexadecimal numbers using "sort" command? (9 Replies)
Discussion started by: Kesavan
9 Replies

7. Shell Programming and Scripting

How to Sort Floating Numbers Using the Sort Command?

Hi to all. I'm trying to sort this with the Unix command sort. user1:12345678:3.5:2.5:8:1:2:3 user2:12345679:4.5:3.5:8:1:3:2 user3:12345687:5.5:2.5:6:1:3:2 user4:12345670:5.5:2.5:5:3:2:1 user5:12345671:2.5:5.5:7:2:3:1 I need to get this: user3:12345687:5.5:2.5:6:1:3:2... (7 Replies)
Discussion started by: daniel.gbaena
7 Replies

8. UNIX for Dummies Questions & Answers

using Unix sort command

Hi I am having some difficulties with the UNIX sort command. I want to sort one a file that looks like this (file A): tiger 5 6 3 5 2 bear 4 5 2 1 8 lions 9 2 5 3 1 dogs 8 5 3 3 1 acccording to a file that looks like this (file B): dogs lions tiger bear So... (2 Replies)
Discussion started by: phil_heath
2 Replies

9. Shell Programming and Scripting

File size limitation of unix sort command.

hi , iam trying to sort millions of records which is delimited and i cant able to use sort command more than 60 million..if i try to do so i got an message stating that "File size limit exceeded",Is there any file size limit for using sort command.. How can i solve this problem. thanks ... (7 Replies)
Discussion started by: cskumar
7 Replies
Login or Register to Ask a Question