| |||
| Getting loc Hi, I have asked this question before but cannot find the thread on Google Groups. Basicaly I want a line of shell code that counts the number of non blank lines of code in a file, directory or directory tree. Many thanks in advance, Aaron |
| |||
| Re: Getting loc In alt.os.linux, Aaron Gray wrote: > Hi, > > I have asked this question before but cannot find the thread on Google > Groups. > > Basicaly I want a line of shell code that counts the number of non blank > lines of code in a file, directory or directory tree. First off, define what you mean by "non blank lines of code". Some questions to consider: /What/ code? (shell script code? java? c++? c? perl? awk? TCL? each language has it's own concept of what a "line of code" consists of) Do compound statements count as one line or multiple lines? (Consider what the C " { something(); something_else(); result=third_thing(); } " means; is this one, three, four, or five lines of code? How do you distinguish a "line of code" from other, extraneous lines? (How do you handle comment lines, for instance?) How do you want to accomodate "included" files (i.e. source files that one /or more/ other sources "#include")? Do you count lines once in each of these files, or do you count them for each time the source file is included into another source file? Once you've answered these questions, post your responses, and we'll have a better understanding of what it is you want to count. From that, we'll be able to properly provide suggestions on how to count your "lines of code". > Many thanks in advance, > > Aaron -- Lew Pitcher Master Codewright & JOAT-in-training | Registered Linux User #112576 http://pitcher.digitalfreehold.ca/ | GPG public key available by request ---------- Slackware - Because I know what I'm doing. ------ |
| |||
| Re: Getting loc In alt.os.linux, Benny Nielsen wrote: > Aaron Gray wrote: > >> Hi, >> >> I have asked this question before but cannot find the thread on Google >> Groups. >> >> Basicaly I want a line of shell code that counts the number of non blank >> lines of code in a file, directory or directory tree. >> >> Many thanks in advance, >> >> Aaron > > cat file(s) | grep -v '^$' | wc -l 1) Useless use of cat Try grep -v '^$' file | wc -l or grep -v -R '^$' directory | wc -l 2) doesn't properly solve the problem a) miscounts comments as lines of code b) doesn't properly count lines of code ~/tmp $ cat file.c /* ** this ** is ** a ** very ** long ** comment */ int main(void) { return 0;} ~/tmp $ cat file.c | grep -v '^$' | wc -l 9 Result should be either 1 or 2, depending on OP's definition of "line of code" -- Lew Pitcher Master Codewright & JOAT-in-training | Registered Linux User #112576 http://pitcher.digitalfreehold.ca/ | GPG public key available by request ---------- Slackware - Because I know what I'm doing. ------ |
| |||
| Re: Getting loc Aaron Gray wrote: > Hi, > > I have asked this question before but cannot find the thread on Google > Groups. > > Basicaly I want a line of shell code that counts the number of non blank > lines of code in a file, directory or directory tree. > > Many thanks in advance, > > Aaron cat file(s) | grep -v '^$' | wc -l |
| |||
| Re: Getting loc "Lew Pitcher" <lpitcher@teksavvy.com> wrote in message news:498ce$484aacdc$4c0a8c73$12692@TEKSAVVY.COM-Free... > In alt.os.linux, Aaron Gray wrote: > >> Hi, >> >> I have asked this question before but cannot find the thread on Google >> Groups. >> >> Basicaly I want a line of shell code that counts the number of non blank >> lines of code in a file, directory or directory tree. > > First off, define what you mean by "non blank lines of code". > Some questions to consider: > /What/ code? (shell script code? java? c++? c? perl? awk? TCL? each > language has it's own concept of what a "line of code" consists of) C++ > Do compound statements count as one line or multiple lines? (Consider > what the C " { something(); something_else(); result=third_thing(); } " > means; is this one, three, four, or five lines of code? 1 > How do you distinguish a "line of code" from other, extraneous lines? > (How do you handle comment lines, for instance?) Comments can be counted too. > How do you want to accomodate "included" files (i.e. source files that > one /or more/ other sources "#include")? Do you count lines once in each > of these files, or do you count them for each time the source file is > included into another source file? Only once. > Once you've answered these questions, post your responses, and we'll have > a > better understanding of what it is you want to count. From that, we'll be > able to properly provide suggestions on how to count your "lines of code". I have used "grep -v -R '^$' directory | wc -l" which gives about 640000 lines of code in the project. I was just after a ready reconer. Thanks, Aaron |
| |||
| Re: Getting loc On 2008-06-07, Aaron Gray <ang.usenet******.com> wrote: > "Lew Pitcher" <lpitcher@teksavvy.com> wrote in message > news:498ce$484aacdc$4c0a8c73$12692@TEKSAVVY.COM-Free... >> In alt.os.linux, Aaron Gray wrote: >> >>> Hi, >>> >>> I have asked this question before but cannot find the thread on Google >>> Groups. >>> >>> Basicaly I want a line of shell code that counts the number of non blank >>> lines of code in a file, directory or directory tree. > I have used "grep -v -R '^$' directory | wc -l" which gives about 640000 > lines of code in the project. Bug: That counts a line with (only) whitespace as a line of code. Try '^[ ]*$' instead. Note that is a space and a tab inside the brackets. Cheers. Jim |
![]() |
| Bookmarks |
| Thread Tools | |
| |