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

  • 相关阅读:
    [CISCN2019 华北赛区 Day1 Web2]ikun
    [BJDCTF 2nd]简单注入
    [BJDCTF2020]ZJCTF,不过如此
    [BJDCTF2020]The mystery of ip
    [SWPU2019]Web1
    [WesternCTF2018]shrine
    [BJDCTF 2nd]假猪套天下第一
    [BJDCTF2020]Mark loves cat
    [GWCTF 2019]我有一个数据库
    C语言学习笔记_函数与函数库
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14672505.html
Copyright © 2011-2022 走看看