Linux 指令篇:文本排序--sort

NAME
    sort - sort lines of text files

SYNOPSIS
    sort [OPTION]... [FILE]...
    sort [OPTION]... --files0-from=F

DESCRIPTION
    Write sorted concatenation of all FILE(s) to standard output.

    Mandatory arguments to long options are mandatory for short options too. Ordering options:

    -f, --ignore-case
      fold lower case to upper case characters

    -n, --numeric-sort
      compare according to string numerical value

    -r, --reverse
      reverse the result of comparisons

    -k, --key=POS1[,POS2]
      start a key at POS1 (origin 1), end it at POS2 (default end of line)

    -t, --field-separator=SEP
      use SEP instead of non-blank to blank transition

    -u, --unique
      with -c, check for strict ordering; without -c, output only the first of an equal run

===============================================================

e.g.1

[root@localhost tmp]# sort num.txt
11
132
132
43
457
667
999

[root@localhost tmp]# sort -n num.txt
11
43
132
132
457
667
999

[root@localhost tmp]# sort -n -u num.txt
11
43
132
457
667
999

[root@localhost tmp]# sort -n -u -r num.txt
999
667
457
132
43
11

==============================================================

e.g.2

[root@localhost tmp]# sort passwd
bin:x:62:1:bin:/bin:/sbin/nologin
daemon:x:222:2:daemon:/sbin:/sbin/nologin
root:x:36:0:root:/root:/bin/bash

 

[root@localhost tmp]# sort -t: -k3 passwd
daemon:x:222:2:daemon:/sbin:/sbin/nologin
root:x:36:0:root:/root:/bin/bash
bin:x:62:1:bin:/bin:/sbin/nologin

 

[root@localhost tmp]# sort -n -t: -k3 passwd
root:x:36:0:root:/root:/bin/bash
bin:x:62:1:bin:/bin:/sbin/nologin
daemon:x:222:2:daemon:/sbin:/sbin/nologin

 

posted @ 2014-04-24 09:42  CloudPing  阅读(270)  评论(0编辑  收藏  举报