sort 命令详解

Posted morgan363

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sort 命令详解相关的知识,希望对你有一定的参考价值。

 

sort 命令

        sort 命令是在Linux里非常有用,它将文件进行排序,并将排序结果标准输出。sort命令既可以从特定的文件,也可以从stdin中获取输入。

 

语法

        sort (选项) (参数)

 

选项

-b:忽略每行前面开始出的空格字符;
-c:检查文件是否已经按照顺序排序;
-d:排序时,处理英文字母、数字及空格字符外,忽略其他的字符;
-f:排序时,将小写字母视为大写字母;
-i:排序时,除了040至176之间的ASCII字符外,忽略其他的字符;
-m:将几个排序号的文件进行合并;
-M:将前面3个字母依照月份的缩写进行排序;
-n:依照数值的大小排序;
-o<输出文件>:将排序后的结果存入制定的文件;
-r:以相反的顺序来排序;
-t<分隔字符>:指定排序时所用的栏位分隔字符;
+<起始栏位>-<结束栏位>:以指定的栏位来排序,范围由起始栏位到结束栏位的前一栏位。

 

SORT(1)                          User Commands                         SORT(1)

NAME
       sort - sort lines of text files

SYNOPSIS
       sort [OPTION]... [FILE]...

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

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

       -b, --ignore-leading-blanks
              ignore leading blanks

       -d, --dictionary-order
              consider only blanks and alphanumeric characters

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

       -g, --general-numeric-sort
              compare according to general numerical value

       -i, --ignore-nonprinting
              consider only printable characters

       -M, --month-sort
              compare (unknown) <  < ... < 

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

       -r, --reverse
              reverse the result of comparisons

       Other options:

       -c, --check
              check whether input is sorted; do not sort

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

       -m, --merge
              merge already sorted files; do not sort

       -o, --output=FILE
              write result to FILE instead of standard output

       -s, --stable
              stabilize sort by disabling last-resort comparison

       -S, --buffer-size=SIZE
              use SIZE for main memory buffer

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

       -T, --temporary-directory=DIR
              use DIR for temporaries, not $TMPDIR or /tmp; multiple options specify multiple directories

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

       -z, --zero-terminated
              end lines with 0 byte, not newline

       --help display this help and exit

       --version
              output version information and exit

       POS  is  F[.C][OPTS],  where  F  is  the  field  number and C the character position in the field.  OPTS is one or more single-letter ordering
       options, which override global ordering options for that key.  If no key is given, use the entire line as the key.

       SIZE may be followed by the following multiplicative suffixes: % 1% of memory, b 1, K 1024 (default), and so on for M, G, T, P, E, Z, Y.

       With no FILE, or when FILE is -, read standard input.

       *** WARNING *** The locale specified by the environment affects sort order.  Set LC_ALL=C to get the traditional sort order that  uses  native
       byte values.

AUTHOR
       Written by Mike Haertel and Paul Eggert.

REPORTING BUGS
       Report bugs to <bug-coreutils@gnu.org>.

COPYRIGHT
       Copyright © 2006 Free Software Foundation, Inc.
       This   is   free   software.    You   may   redistribute   copies   of   it   under   the   terms   of   the   GNU   General   Public  License
       <http://www.gnu.org/licenses/gpl.html>.  There is NO WARRANTY, to the extent permitted by law.

SEE ALSO
       The full documentation for sort is maintained as a Texinfo manual.  If the info and sort programs are properly installed  at  your  site,  the
       command

              info sort

       should give you access to the complete manual.

sort 5.97                          July 2011                           SORT(1)

 

参数

        文件:指定待排序的文件列表。

 

实例

        sort将文件/文本的每一行作为一个单位,相互比较,比较原则是从首字符向后,依次按ASCII码值进行比较,最后将他们按升序输出。

以上是关于sort 命令详解的主要内容,如果未能解决你的问题,请参考以下文章

[转]linux sort 命令详解

sort 命令详解

linux sort 命令详解

linux sort 命令详解

sort命令详解

linux sort,uniq,cut,wc命令详解