How to sort a column in UNIX that is colon separated ":" ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to sort a column in UNIX that is colon separated ":" ?
# 1  
Old 12-14-2012
How to sort a column in UNIX that is colon separated ":" ?

Experts, how to sort this fields with numerical order :
-How to use the sort command in this case, I was thinking with -k but it is not working,


Code:
lan5000     
lan5000:1   
lan5000:10  
lan5000:11  
lan5000:12  
lan5000:13  
lan5000:14  
lan5000:15  
lan5000:16  
lan5000:17  
lan5000:18  
lan5000:19  
lan5000:2   
lan5000:20  
lan5000:21  
lan5000:22  
lan5000:23  
lan5000:24  
lan5000:3   
lan5000:4   
lan5000:5   
lan5000:6   
lan5000:7   
lan5000:8   
lan5000:9


The output should be :

Code:
lan5000:1
lan5000:2  
lan5000:3

and so on....


Thank you,
RVeri.

Last edited by joeyg; 12-14-2012 at 04:28 PM.. Reason: Corrected title spelling
# 2  
Old 12-14-2012
Code:
sort -t: -n inputfile

# 3  
Old 12-14-2012
Corona688,
Thanks for quick answer,
But " sort -t: -n inputfile " doesn't work.


Output below:
Code:
servera5>cat f1
lan5000:1  
lan5000:10 
lan5000:11 
lan5000:12 
lan5000:13 
lan5000:14 
lan5000:15 
lan5000:16 
lan5000:17 
lan5000:18 
lan5000:19 
lan5000:2  
lan5000:20 
lan5000:21 
lan5000:22 
lan5000:23 
lan5000:24 
lan5000:3  
lan5000:4  
lan5000:5  
lan5000:6  
lan5000:7  
lan5000:8  
lan5000:9


Code:
servera5> sort -t: -n f1
lan5000:1  
lan5000:10 
lan5000:11 
lan5000:12 
lan5000:13 
lan5000:14 
lan5000:15 
lan5000:16 
lan5000:17 
lan5000:18 
lan5000:19 
lan5000:2  
lan5000:20 
lan5000:21 
lan5000:22 
lan5000:23 
lan5000:24 
lan5000:3  
lan5000:4  
lan5000:5  
lan5000:6  
lan5000:7  
lan5000:8  
lan5000:9

# 4  
Old 12-14-2012
Sorry, forgot one parameter.

Code:
sort -t: -k 2,2 -n inputfile

# 5  
Old 12-14-2012
Code:
sort -t':' -n -k2 f1

# 6  
Old 12-14-2012
Quote:
Originally Posted by Corona688
Sorry, forgot one parameter.

Code:
sort -t: -k 2,2 -n inputfile

Corona688,
Sorry this still didn't work:
Below output,


Code:
# sort -t: -k 2,2 -n f1
Usage: sort [-AbcdfiMmnru] [-T Directory] [-tCharacter] [-y kilobytes] [-o File]
           [-k Keydefinition].. [[+Position1][-Position2]].. [-z recsz] [File]..

SOLUTION:
- The next post from bipinajith worked like a charm.
Solution accepted : sort -t':' -n -k2 f1 .

Thanks to all.
# 7  
Old 12-16-2012
Code:
sort -t: -k2n infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract delta records using with "comm" and "sort" commands combination

Hi All, I have 2 pipe delimited files viz., file_old and file_new. I'm trying to compare these 2 files, and extract all the different rows between them into a new_file. comm -3 < sort file_old < sort file_new > new_file I am getting the below error: -ksh: sort: cannot open But if I do... (7 Replies)
Discussion started by: njny
7 Replies

2. Shell Programming and Scripting

awk :help to parse a file to change to separated by colon ":"

Hi experts , I am trying to get the below output: file : 0/6/4/1 0x0019503C2E26 5 UP lan5 snap5 1 ETHER Yes 224 0/6/4/0 0x0019503C2E25 6 UP lan6 snap6 2 ETHER Yes 224 0/2/1/0 0x0019503E6900 0 UP lan0 snap0 3 ETHER Yes 224... (8 Replies)
Discussion started by: rveri
8 Replies

3. Shell Programming and Scripting

How to allign output data in UNIX that is separated with a pipe "|" symbol ?

Experts , In the given output of the log file, the 2nd field that is separated by "|" pipe is not aligned well due to the uneven data length, I would like it to align the 2nd column with 37 length (that is disturbed in the output) including the pipe . The two pepe "|" would be in a aligned way... (2 Replies)
Discussion started by: rveri
2 Replies

4. Shell Programming and Scripting

Substituting comma "," for dot "." in a specific column when comma"," is a delimiter

Hi, I'm dealing with an issue and losing a lot of hours figuring out how i would solve this. I have an input file which looks like this: ('BLABLA +200-GRS','Serviço ','TarifaçãoServiço','wap.bla.us.0000000121',2985,0,55,' de conversão em escada','Dia','Domingos') ('BLABLA +200-GRR','Serviço... (6 Replies)
Discussion started by: poliver
6 Replies

5. AIX

AIX HMC - Getting Colon ":" in output

Hi, I am executing below commands on HMC. I see that there is only colon ":" in output. Can someone please help why I am getting ":" in output? Why I am not getting proper output? xxxxx@yyyyhmc1:~> viosvrcmd -m PCC-p590#2-SN024D8F0 -p ppvio1 -c "lsmap -all" :xxxxx@yyyyhmc1:~> viosvrcmd... (0 Replies)
Discussion started by: marya
0 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

Meaning of "b" modifier in "sort" command

I need to sort the following file by the rhdiskpower devices in the last column: Total_MB Free_MB OS_MB Name Failgroup Library Label UDID Product Redund Path 1024 851 1024 OCRVOT1_0000 OCRVOT1_0000 System UNKNOWN ... (3 Replies)
Discussion started by: wjssj
3 Replies

8. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

9. Shell Programming and Scripting

How to cut a file using " ", but fields can be separated with more than one " "

Hello, let's say I have a text file: word11 word12 word13 word21 word22 word23 word31 word32 word33 and I want to put the second field of each line into a list: set list = `cut -d" " -f2 ${1}` and I use space (" ") as a delimiter, only that there's a catch: there can be more than... (12 Replies)
Discussion started by: shira
12 Replies

10. UNIX for Advanced & Expert Users

Commands on Digital Unix equivalent to for "top" and "sar" on other Unix flavour

Hi, We have a DEC Alpha 4100 Server with OSF1 Digital Unix 4.0. Can any one tell me, if there are any commands on this Unix which are equivalent to "top" and "sar" on HP-UX or Sun Solaris ? I am particularly interested in knowing the CPU Load, what process is running on which CPU, etc. ... (1 Reply)
Discussion started by: sameerdes
1 Replies
Login or Register to Ask a Question