2012-07-28

Linux Command : Sort

2012-07-20  R.J' Wiki : Debian (Linux) Command : Sort

sort:排序(對檔案的每一列排序)
用法 : sort [參數] 檔案
參數 	說明
-r 	大→小
-n 	數字
-k n 	依欄位n 

例:

  • data File(data.txt)
    09:45 7051 7005 15 7016
    10:00 7121 7061 24 7086
    10:05 7082 7026 35 7047
    09:30 7263 7210 31 7228
    09:25 7164 7124 32 7129
    11:50 7503 7422 33 7468
    09:50 7750 7693 30 7715
    10:10 7750 7682 25 7715
    09:20 7928 7876 23 7893
    10:30 7994 7955 20 7959
    
  • 依第4欄排序
    sort -k4 data.txt
    
    結果
    09:45 7051 7005  15 7016
    10:30 7994 7955  20 7959
    09:20 7928 7876  23 7893
    10:00 7121 7061  24 7086
    10:10 7750 7682  25 7715
    09:50 7750 7693  30 7715
    09:30 7263 7210  31 7228
    09:25 7164 7124  32 7129
    11:50 7503 7422  33 7468
    10:05 7082 7026  35 7047
    

    ---

沒有留言: