linux初學 進階檔案管理 wc uniq cut diff sort tr

來源:互聯網
上載者:User

標籤:檔案管理wc uniq cut diff sort tr

  wc 計算檔案的行數,單詞數,位元組數

         # wc /etc/passwd

           40   59 1800 /etc/passwd

         # wc -l /etc/passwd

           40 /etc/passwd

         # wc -w /etc/passwd

           59 /etc/passwd

         # wc -c /etc/passwd

           1800 /etc/passwd

 

 grep正則介紹


           ^  行首

           $  行尾

           v  取反

           n  顯示行號

           c  統計行數

                  

       diff 對比兩檔案的差異

         d 刪除了(delete) -a 新增了(append) -c 改變了(change)

         cp /etc/passwd passwd1

         刪幾行 改幾行 加幾行看看效果

         diff /etc/passwd passwd1


     uniq  對檔案去重

        uniq -c file    顯示file檔案中重複的行出現的次數 count 次數

        uniq -d  file    只顯示重複的行,沒重複的不顯示


      cut 按列提取檔案

         -d 指明資料行分隔符號 -f 選擇輸出的地區 -c 指定字元位置

         # cut -d: -f 1,7 /etc/passwd |head -n 2

             root:/bin/bash

             bin:/sbin/nologin

         # cut -c 1-3,6-9 /etc/passwd |head -n 2


         tr 字元的刪除替換

          -d 刪除

          # tr -d :  < /etc/passwd |head -n 2

          替換

          # tr ‘abc‘ ‘ABC‘  < /etc/passwd |head -n 2

          # tr ‘abc‘  ‘A‘ < /etc/passwd |head -n 2

          # tr ‘a-z‘ ‘A-Z‘  < /etc/passwd |head -n 2


         sort 排序輸出

          預設按首字元從頭至尾的順序排序

          -r 逆序

      -u去重

          -n 按數字排序

          -t 指明分隔字元 與 -k 連用

          -k 按指定的域排序

         # sort -t: -k 3 /etc/passwd  


       split分割檔案 分割檔案名稱為xaa

   -b(位元組) 大小

-l 行數

 

 



linux初學 進階檔案管理 wc uniq cut diff sort tr

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.