程式扎記: [Linux 常見問題] Count number of blank lines in a file

標籤

2016年12月1日 星期四

[Linux 常見問題] Count number of blank lines in a file

Source From Here
Question
In count (non-blank) lines-of-code in bash they explain how to count the number of non-empty lines.
But is there a way to count the number of blank lines in a file? By blank line I also mean lines that have spaces in them.

How-To
Another way is:
# grep -cvP '\S' file
// -P '\S'(perl regex) will match any line contains non-space
// -v select non-matching lines
// -c print a count of matching lines


沒有留言:

張貼留言

網誌存檔

關於我自己

我的相片
Where there is a will, there is a way!