To count a number of lines in C++ or Java or ASCII files by exluding white spaces and comments

J

John Smith

Hi all,

We have huge files in Java and C++ and I need to count the total
number of lines in each of them by excluding white spaces (from the
beginning of a line) and comments (C++, Java comments etc).

There must be some scripts in perl to do this job.

Can anyone kindly let me know? Or, are there any third-party tools to
do this job?

Thanks,
John
 
B

Bob Walton

John Smith wrote:

....

We have huge files in Java and C++ and I need to count the total
number of lines in each of them by excluding white spaces (from the
beginning of a line) and comments (C++, Java comments etc).

There must be some scripts in perl to do this job.

Can anyone kindly let me know? Or, are there any third-party tools to
do this job? ....


John

Most of this is a FAQ, at least for the C++ part:

perldoc -q comment

Maybe that'll be good enough for Java too?

Removing blank lines can be done with

next if /^\s*$/;

assuming you are reading and processing your lines in a loop.
 
J

John Smith

Bob Walton said:
John Smith wrote:

...



Most of this is a FAQ, at least for the C++ part:

perldoc -q comment

Maybe that'll be good enough for Java too?

Removing blank lines can be done with

next if /^\s*$/;

assuming you are reading and processing your lines in a loop.

Thanks Bob!

I am looking out for a third party tool t odo this job. We have
millions of code in one of our Parent directory. I want a total count
of lines, number of blank lines and number of comments in the entire
folder. I am not tlaking about a single file.

Thanks,
John
 
J

John W. Krahn

John said:
We have huge files in Java and C++ and I need to count the total
number of lines in each of them by excluding white spaces (from the
beginning of a line) and comments (C++, Java comments etc).

There must be some scripts in perl to do this job.

Can anyone kindly let me know? Or, are there any third-party tools to
do this job?

http://www.dwheeler.com/sloccount/


John
 
A

Alex Vinokur

We have huge files in Java and C++ and I need to count the total
number of lines in each of them by excluding white spaces (from the
beginning of a line) and comments (C++, Java comments etc).
There must be some scripts in perl to do this job.
Can anyone kindly let me know? Or, are there any third-party tools to
do this job?
Thanks,
John

Look at "Counter of C/C++ code" :
* http://groups.google.com/[email protected]
* http://alexvn.freeservers.com/s1/download.html#label1_cncc
* http://groups.google.com/[email protected]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top