The most crude version
Shell Code
Find. -name "*.java" |xargs wc-l|grep "Total" |awk ' {print $} ' find
.-name "*.java" |xargs cat|wc-l #Output: 37634
The above two sentences are the same, but the second one is to use cat to merge the contents of multiple Java files into the output. and then statistics.
But two have a common problem--even the blank line in the file to count into a row.
Remove empty row version
Shell Code
Find. -name "*.java" |xargs cat|grep-v ^$|wc-l #Output: 36335
This version is a bit more reliable, you can see the results of the blank line after the result has been changed: 36335, compared to the previous version of the 1299 rows of empty lines killed ...
However, Java code also has comments ah ... Fuck, you have to kill the note.
Remove annotation Version
Shell Code
# Exclude the lines begin with//find
.-name "*.java" |xargs cat|grep-v-E ^$-e ^\s*\/\/.*$|wc-l #Output: 36064
Well, this method finds that the comment beginning with//has a 36335-36064=271 line. It should be noted here that the comment line does not necessarily take//as the beginning, perhaps n a space after the start of the//, so the match needs to add the above ^\s* at the beginning.
It's done. Nonsense ...
Java comments in several styles, and then show you this very common annotation, or will be in the statistical results
Java code
/**
* @author xxx 2012-6-15 pm 3:19:47 * *
What the hell. This annotation I really did not think how to easily remove, simple and rough method but can be in the above grep parameter inside add 3 more regular, divided by/*,,, * *, the beginning of the line.
Turn from: http://blog.csdn.net/wzygis/article/details/49797835