10

我有一个文件,其列如下所示:

chr1  91.4062
chr10  97.9150
chr11 116.7630
chr12 106.7870
chr13 116.1050
chr14 126.2180
chr15 110.2320
chr16  96.8076
chr17 113.5970
chr18  86.1011
chr19 130.6770
chr2 111.4620
chr20  68.4864
chr21 107.0810
chr22 140.7750
chr23 110.9590
chr24  68.4785
chr25 102.2080
chr26  72.2762
chr27  96.2213
chr28  85.5570
chr29 126.3800
chr3 116.1830
chr30  89.5663
chr31  89.1227
chr32 128.6190
chr4 117.3620
chr5  78.1921
chr6  85.4915
chr7 107.2620
chr8 112.9560
chr9  69.0250
chrX  66.0736

我想根据第一列对其进行排序,输出应如下所示:

chr1 91.4062
chr2 111.4620
chr3 116.1830
chr4 117.3620
chr5 78.1921
chr6 85.4915
chr7 107.2620
chr8 112.9560
chr9 69.0250
chr10 97.9150
chr11 116.7630
chr12 106.7870
chr13 116.1050
chr14 126.2180
chr15 110.2320
chr16 96.8076
chr17 113.5970
chr18 86.1011
chr19 130.6770
chr20 68.4864
chr21 107.0810
chr22 140.7750
chr23 110.9590
chr24 68.4785
chr25 102.2080
chr26 72.2762
chr27 96.2213
chr28 85.5570
chr29 126.3800
chr30 89.5663
chr31 89.1227
chr32 128.6190
chrX 66.0736

任何使用 linux 命令的解决方案都会有所帮助。

4

1 回答 1

22

sort -V救援:

sort -V file

来自man sort

-V,--版本排序

文本中(版本)数字的自然排序


如果您的命令中没有该-V选项sort,则有另一种选择:从第 4 个字符 ( ) 开始按第一列排序-k1.4,然后按数字排序 ( -n)。

sort -k1.4 -n file

在这两种情况下,输出如下:

chrX  66.0736
chr1  91.4062
chr2 111.4620
chr3 116.1830
chr4 117.3620
...
chr26  72.2762
chr27  96.2213
chr28  85.5570
chr29 126.3800
chr30  89.5663
chr31  89.1227
chr32 128.6190
于 2013-08-19T08:36:36.273 回答