天天看點

linux統計檔案每行長度,wc指令 – 統計檔案的位元組數、字數、行數

wc指令統計指定檔案中的位元組數、字數、行數,并将統計結果顯示輸出。利用wc指令我們可以計算檔案的Byte數、字數或是列數,若不指定檔案名稱,或是所給予的檔案名為“-”,則wc指令會從标準輸入裝置讀取資料。wc同時也給出所指定檔案的總統計數。

文法格式:wc [參數] [檔案]

常用參數:

-w統計字數,或--words:隻顯示字數。一個字被定義為由空白、跳格或換行字元分隔的字元串

-c統計位元組數,或--bytes或--chars:隻顯示Bytes數

-l統計行數,或--lines:隻顯示列數

-m統計字元數

-L列印最長行的長度

--help顯示幫助資訊

--version顯示版本資訊

參考執行個體

統計字數:

[[email protected] ~]# cat test.txt

hello world

hello world

hello world

hello world hello world

[[email protected] ~]# wc -w test.txt

10 test.txt

統計位元組數:

[[email protected] ~]# wc -c test.txt

60 test.txt

統計字元數:

[[email protected] ~]# wc -m test.txt

60 test.txt

統計行數:

[[email protected] ~]# wc -l test.txt

4 test.txt

列印最長行的長度:

[[email protected] ~]# wc -L test.txt

23 test.txt