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

 

转载于:https://www.cnblogs.com/CloudPing/p/3684674.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值