天天看點

linux wc -l指令

文法
[[email protected] shell]# wc --help
用法:wc [選項]... [檔案]...
 或:wc [選項]... --files0-from=F
輸出每個指定檔案的行數、單詞計數和位元組數,如果指定了
多于一個檔案,繼續給出所有相關資料的總計。如果沒有指定
檔案,或者檔案為"-",則從标準輸入讀取資料。
  -c, --bytes		輸出位元組數統計
  -m, --chars		輸出字元數統計
  -l, --lines		輸出行數統計
      --files0-from=檔案	從指定檔案讀取以NUL 終止的名稱,如果該檔案被
					指定為"-"則從标準輸入讀檔案名
  -L, --max-line-length	顯示最長行的長度
  -w, --words			顯示單詞計數
      --help		顯示此幫助資訊并退出
      --version		顯示版本資訊并退出
           
執行個體
[[email protected] shell]# cat stu.txt 
100:zhangsan:nan:jisuanji
101:zhanghong:nv:wenmi
[[email protected] shell]# cat stu.txt | wc -l       //檔案行數
2
[[email protected] shell]# cat stu.txt | sed -n '1p'   //sed輸出第1行
100:zhangsan:nan:jisuanji
[[email protected] shell]# cat stu.txt | sed -n '1p'| wc -L  //第一行的長度,:也算
25
[[email protected] shell]# cat stu.txt | sed  -n '1p'| sed 's/[^0-9]//g'  //隻保留數字
100
[[email protected] shell]# cat stu.txt | sed  -n '1p'| sed 's/[^0-9]//g'| wc -L   //數字的長度
3