make sort of a file with multiple columns

2

Hello, I need to sort from my file, I have 3 columns: the first would be the chromosome (1,2,3,4,5..28, W, Z), the second would be the position on this chromosome and the last one they would be values.

When I do the sort -n I have the chromosomes drawn in 10,11,12,13 .... but I want the order: 1,2,3 ... 28, W, Z. The second column would like the values from lowest to highest. The third column does not matter.

Example of my input

10      247     0.02                      
10      445     0.04                   
10      447     0.08         
11      81     0.04      
11      91     0.01   
1      102     0.03  
1      105     0.05 

What would be the best command?

    
asked by anonymous 14.09.2015 / 17:40

1 answer

2

You can use the -V (--version-sort) option of the sort command to get the desired output.

From the manual:

-V, --version-sort
         natural sort of (version) numbers within text

Assuming your file is named ficheiroInput and contains the following content

A       131     0.01
10      247     0.02                      
10      447     0.04                   
10      445     0.08         
11       81     0.04      
11       91     0.01   
1       105     0.03  
1       102     0.05 
W       202     0.06

The command

cat ficheiroInput | sort -k1,1 -V -k2,2  

will produce this output:

1       102     0.05 
1       105     0.03  
10      247     0.02                      
10      445     0.08         
10      447     0.04                   
11       81     0.04      
11       91     0.01   
A       131     0.01
W       202     0.06
    
14.09.2015 / 21:50