簡明Linux命令列筆記:sort

來源:互聯網
上載者:User
文章目錄
  • 參數
  • 選項
  • 樣本

對檔案排序

sort [options] [file-list]

 

參數

file-list是需要排序的檔案路徑名,如果省略file-list,則sort將從標準輸入擷取輸入

 

選項

-b              忽略開頭的空白符

-c               檢查檔案是否已排序,如果排好則不顯示任何訊息

-d               忽略除字母、數字和空白符外的所有字元

-f                將所有的消協字母看作是大寫字母

-k                按照指定的欄位對某一行進行排序

-n                按照算數列排序

-r                 按逆序排序

-u                重複行僅輸出一次

 

樣本

原檔案

$ cat list Tom Winstrom         94201Janet Dempsey        94111Alice MacLeod        94114David Mack           94114Toni Barnett         95020Jack Cooper          94072Richard MacDonald    95510

 

sort
$ sort list Alice MacLeod        94114David Mack           94114Jack Cooper          94072Janet Dempsey        94111Richard MacDonald    95510Tom Winstrom         94201Toni Barnett         95020

預設按字母順序排序

 

sort -k
$ sort -k 2 list Toni Barnett         95020Jack Cooper          94072Janet Dempsey        94111Richard MacDonald    95510David Mack           94114Alice MacLeod        94114Tom Winstrom         94201

按指定的欄位排序

 

sort -f
$ sort -f list Alice MacLeod        94114David Mack           94114Jack Cooper          94072Janet Dempsey        94111Richard MacDonald    95510Tom Winstrom         94201Toni Barnett         95020

不區分大小寫排序

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.