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

  • 相关阅读:
    SQL的介绍及MySQL的安装
    git中级技能
    git基本用法
    git基本语法
    出租车数据分析
    使用Spark MLlib进行情感分析
    增量式编码器专题
    vue-loader的简单例子
    node爬虫(转)
    fs-extra 文件管理
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14672505.html
Copyright © 2011-2022 走看看