0

I have a file that contain the following content:

type1
type2
type4
type15
type13
type10
type9
type8
type3
type5
type6
type7
type11
type12
type14

I used this command to get a sorted content cat file|sort -u

but I have the following result:

$cat file|sort -u
type1
type10
type11
type12
type13
type14
type15
type2
type3
type4
type5
type6
type7
type8
type9

What is the right command to get the following result?

type1
type2
type3
type4
type5
type6
type7
type8
type9
type10
type11
type12
type13
type14
type15

This my sort command help:

root@router:~# sort --help
BusyBox v1.19.2 (2013-05-20 07:23:28 CEST) multi-call binary.

Usage: sort [-nru] [FILE]...

Sort lines of text

        -n      Sort numbers
        -r      Reverse sort order
        -u      Suppress duplicate lines
4

2 回答 2

3

This should do it:

sort -u -k 1.5n file

The -k option specifies the sort key. 1.5 means that it starts from character 5 of column 1 of the input, and n means that it should do a numeric sort instead of lexicographic.

于 2013-07-24T08:57:28.177 回答
1

Try coreutils-sort package.

opkg install coreutils-sort -force-overwrite 
于 2014-05-11T18:37:24.657 回答