Help with sort alphabet on specific column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with sort alphabet on specific column
# 1  
Old 02-26-2013
Help with sort alphabet on specific column

Input file:
Code:
POL     B7U6K8  Avian_reticuloendotheliosis_virus
POLB    B7Z1W5  Homo_sapiens
POLB    H9G5Y0  Anolis_carolinensis
POLD1   Q642R8  Xenopus_laevis
POLD2   H0YZC7  Taeniopygia_guttata
POLD3   F1P540  Gallus_gallus
POLDIP3 Q5F4B6  Gallus_gallus
POLE2   E1C2T8  Gallus_gallus
POLE3   F1P2L0  Gallus_gallus
POL     E6ZGJ1  Dicentrarchus_labrax
POL     E6ZGJ4  Dicentrarchus_labrax
POLE    E1C5P2  Gallus_gallus
POLE    G1RBL5  Nomascus_leucogenys
POL     F4Y5K7  Avian_reticuloendotheliosis_virus

Desired output
Code:
POL     B7U6K8  Avian_reticuloendotheliosis_virus
POL     F4Y5K7  Avian_reticuloendotheliosis_virus
POL     E6ZGJ1  Dicentrarchus_labrax
POL     E6ZGJ4  Dicentrarchus_labrax
POLB    H9G5Y0  Anolis_carolinensis
POLB    B7Z1W5  Homo_sapiens
POLD1   Q642R8  Xenopus_laevis
POLD2   H0YZC7  Taeniopygia_guttata
POLD3   F1P540  Gallus_gallus
POLDIP3 Q5F4B6  Gallus_gallus
POLE    E1C5P2  Gallus_gallus
POLE    G1RBL5  Nomascus_leucogenys
POLE2   E1C2T8  Gallus_gallus
POLE3   F1P2L0  Gallus_gallus

Can I know how to sort column 1 and column 3 content at the same time based on alphabet (sort A to Z) ?

Thanks for any advice.
# 2  
Old 02-26-2013
Code:
$ sort -k1 sort.txt
POL     B7U6K8  Avian_reticuloendotheliosis_virus
POL     E6ZGJ1  Dicentrarchus_labrax
POL     E6ZGJ4  Dicentrarchus_labrax
POL     F4Y5K7  Avian_reticuloendotheliosis_virus
POLB    B7Z1W5  Homo_sapiens
POLB    H9G5Y0  Anolis_carolinensis
POLD1   Q642R8  Xenopus_laevis
POLD2   H0YZC7  Taeniopygia_guttata
POLD3   F1P540  Gallus_gallus
POLDIP3 Q5F4B6  Gallus_gallus
POLE    E1C5P2  Gallus_gallus
POLE    G1RBL5  Nomascus_leucogenys
POLE2   E1C2T8  Gallus_gallus
POLE3   F1P2L0  Gallus_gallus

sort has various options like -k is for field and -t sep and -w -n -r ......read man sort for more details....

Thanks
Sha
This User Gave Thanks to Shahul For This Post:
# 3  
Old 02-26-2013
Code:
sort -t" " -k1,2 input_file

This User Gave Thanks to panyam For This Post:
# 4  
Old 02-26-2013
Code:
sort -k1,1 -k3,3 input_file

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using awk to change a specific column and in a specific row

I am trying to change the number in bold to 2400 01,000300032,193631306,190619,0640,1,80,,2/ 02,193631306,000300032,1,190618,0640,CAD,2/ I'm not sure if sed or awk is the answer. I was going to use sed and do a character count up to that point, but that column directly before 0640 might... (8 Replies)
Discussion started by: juggernautjoee
8 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. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

4. Shell Programming and Scripting

How to print multiple specific column after a specific word?

Hello.... Pls help me (and sorry my english) :) So I have a file (test.txt) with 1 long line.... for example: isgc jsfh udgf osff 8462 error iwzr 653 idchisfb isfbisfb sihfjfeb isfhsi gcz eifh How to print after the "error" word the 2nd 4th 5th and 7th word?? output well be: 653 isfbisfb... (2 Replies)
Discussion started by: marvinandco
2 Replies

5. UNIX for Dummies Questions & Answers

Sort command in one column and not effect to another column

If my data is numerical : 1 = 101 2 = 102 3 = 104 4 = 104 7 = 103 8 = 103 9 = 105 I need the result like below: 1 = 101 2 = 102 3 = 103 4 = 103 7 = 104 8 = 104 9 = 105 (4 Replies)
Discussion started by: GeodusT
4 Replies

6. Shell Programming and Scripting

Count specific characters at specific column positions

Hi all, I need help. I have an input text file (input.txt) like this: 21 GTGCAACACCGTCTTGAGAGG 50 21 GACCGAGACAGAATGAAAATC 73 21 CGGGTCTGTAGTAGCAAACGC 108 21 CGAAAAATGAACCCCTTTATC 220 21 CGTGATCCTGTTGAAGGGTCG 259 Now I need to count A/T/G/C numbers at each character location in column... (2 Replies)
Discussion started by: thienxho
2 Replies

7. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

8. 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

9. Shell Programming and Scripting

Insert a text from a specific row into a specific column using SED or AWK

Hi, I am having trouble converting a text file. I have been working for this whole day now, still i couldn't make it. Here is how the text file looks: _______________________________________________________ DEVICE STATUS INFORMATION FOR LOCATION 1: OPER STATES: Disabled E:Enabled ... (5 Replies)
Discussion started by: Issemael
5 Replies

10. UNIX for Dummies Questions & Answers

sort by column or specific order

Hi, I need to sort it by column or need it in a specific order... input is ===== uid=shashi country= india region =0 ph=0 uid= jon region= asia ph= 12345 country=0 uid = man country= india ph=2222 region=0 uid= neera region= asia ph= 125 country=0 output should be uid=shashi ... (1 Reply)
Discussion started by: hegdeshashi
1 Replies
Login or Register to Ask a Question