unix command - bash shell

Hey all,

I need to know how many lines of C code are in a source bundle. I have extracted the bundle and hence there is a big directory tree with C files everywhere.

So far I have something like:

find . -name ".c" | grep \ ./*/*/*/*/*/

obviously wrong, if someone could help me out that would be great thanks!

~ Dan

Assuming you just want line count:

find . -name '*.c' | xargs wc -l | tail -1
or

find . -name '*.c' | xargs awk ' END { print NR } '

Thanks mate, although I ended up doing it with this before you replied:

find . -name ".c" | cat | xargs grep -c "." | awk -F: '{ s+=$2 } END {print "TOTAL: ", s}'

Which I stumbled on by fluke, I look forward to using your simpler version, thanks.

~ Dan

Just in case anyone else needs this post I came up with this as my final solution:

find . -name '*.cpp' | xargs wc -l | grep total | awk -f: '{ s+=$1 } END {print "TOTAL: ", s}'

The solution in the previous post only prints the last total. However on Solaris it prints the "Total" for each sub directory as well. This is handy if you are recursing a deep directory tree.

Cheers,

~ Dan