zoukankan      html  css  js  c++  java
  • linux系统中sort命令

    linux系统中sort命令。

    1、测试数据

    [root@centos7 test2]# cat a.txt
    google 110 5000
    baidu 100 5000
    guge 50 3000
    sohu 100 4500

    2、默认按照第一列排序

    [root@centos7 test2]# sort a.txt
    baidu 100 5000
    google 110 5000
    guge 50 3000
    sohu 100 4500

    3、按照第二列进行排序

    [root@centos7 test2]# cat a.txt
    google 110 5000
    baidu 100 5000
    guge 50 3000
    sohu 100 4500
    [root@centos7 test2]# sort -t " " -k 2n a.txt    ## -t指定分隔符,-k 2 指定列数, n表示按照数值大小进行排序
    guge 50 3000
    baidu 100 5000
    sohu 100 4500
    google 110 5000

    4、先按照第二列排序,在按照第三列排序

    [root@centos7 test2]# cat a.txt
    google 110 5000
    baidu 100 5000
    guge 50 3000
    sohu 100 4500
    [root@centos7 test2]# sort -t " " -k 2n -k 3n a.txt
    guge 50 3000
    sohu 100 4500
    baidu 100 5000
    google 110 5000

    5、先按第三列降序排列,再按照第二列升序排列

    [root@centos7 test2]# cat a.txt
    google 110 5000
    baidu 100 5000
    guge 50 3000
    sohu 100 4500
    [root@centos7 test2]# sort -t " " -k 3nr -k 2n a.txt    ## r表示逆向排序
    baidu 100 5000
    google 110 5000
    sohu 100 4500
    guge 50 3000

    参考:https://www.cnblogs.com/longjshz/p/5797933.html

  • 相关阅读:
    Git的基本使用(只是基本使用)
    GET与POST的比较
    GO开发:链表
    阿里云啊
    以太坊区块和交易存储
    以太坊私有链部署合约
    以太坊go-ethereum签名部分源码解析
    GO开发:接口
    区块链开发:以太坊网络
    Go开发[八]goroutine和channel
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14672505.html
Copyright © 2011-2022 走看看