[Lula] Re: line count for all files in a directory

A. Danial adanial.ae86 at gtalumni.org
Fri Feb 8 23:57:10 EST 2002


HariNam Singh wrote:
> Hi,
> 
> a question for the command line wizards. How can I get a line count of
> all files in a directory? It's easy to do in a script. Though, with
> the command line and piping being so powerful, I would like to be
> enlightened to doing it that way. Also, was it possible to filter out
> all the blank lines, maybe using sed/awk in the same line?
> 
> The purpose is quite simple. I want to know, how many lines of code my
> current project contains.
> 
> Thanks,
> HariNam

I agree with Chris, "All things in life are trivial with Perl."
Here's proof:

  find . -name *.[ch] | xargs perl -n -e 'print unless /^\s*$/'| wc -l

This will descend recursively and count non-blank lines in all your
*.c and *.h files.  If you really just want to count up lines from
code in the current directory (without descending into other
directories) try

  perl -n -e 'print unless /^\s*$/' *.[ch] | wc -l

Of course, replace the *.[ch] regex to match source files that are
of interest to you.

Aside:  thanks to Shane Chen, Martin Baehr, Will Yardley, and John
Wenger for replying to my postfix mail problem.  No, I still haven't
solved the problem.  I'm in the middle of composing a long reply
(hope I finish tonight).              -- Al
_______________________________________________
Lula mailing list
Lula at lula.org
http://www.lula.org/mailman/listinfo/lula


More information about the Lula mailing list