count (non-blank) lines-of-code in bash

Jonathan Hartley picture Jonathan Hartley · Sep 22, 2008 · Viewed 127.3k times · Source

In Bash, how do I count the number of non-blank lines of code in a project?

Answer

Michael Cramer picture Michael Cramer · Sep 22, 2008
cat foo.c | sed '/^\s*$/d' | wc -l

And if you consider comments blank lines:

cat foo.pl | sed '/^\s*#/d;/^\s*$/d' | wc -l

Although, that's language dependent.