Count number of blank lines in a file

前端 未结 7 920
抹茶落季
抹茶落季 2021-02-01 01:38

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

7条回答
  •  花落未央
    2021-02-01 02:16

    To count how many useless blank lines your colleague has inserted in a project you can launch a one-line command like this:

    blankLinesTotal=0; for file in $( find . -name "*.cpp" ); do blankLines=$(grep -cvE '\S' ${file}); blankLinesTotal=$[${blankLines} + ${blankLinesTotal}]; echo $file" has" ${blankLines} " empty lines."  ; done; echo "Total: "${blankLinesTotal}
    

    This prints:

    .cpp #blankLines
    ....
    ....
    .cpp #blankLines
    Total #blankLinesTotal
    

提交回复
热议问题