In Bash, how do I count the number of non-blank lines of code in a project?
相关问题
- JQ: Select when attribute value exists in a bash a
- Why should we check WIFEXITED after wait in order
- bash print whole line after splitting line with if
- “command not found” errors in expect script execut
- grep using grep results
相关文章
- Check if directory exists on remote machine with s
- Making new files automatically executable?
- Reverse four length of letters with sed in unix
- Launch interactive SSH bash session from PHP
- BASH: Basic if then and variable assignment
- Bash script that creates a directory structure
- Test if File/Dir exists over SSH/Sudo in Python/Ba
- Extracting columns from text file using Perl one-l
If you want the sum of all non-blank lines for all files of a given file extension throughout a project:
First arg is the project's base directory, second is the file extension. Sample usage:
It's little more than a collection of previous solutions.
'wc' counts lines, words, chars, so to count all lines (including blank ones) use:
To filter out the blank lines, you can use grep:
'-v' tells grep to output all lines except those that match '^' is the start of a line '\s*' is zero or more whitespace characters '$' is the end of a line *.py is my example for all the files you wish to count (all python files in current dir) pipe output to wc. Off you go.
I'm answering my own (genuine) question. Couldn't find an stackoverflow entry that covered this.
gives an aggregate count for all files in the current directory and its subdirectories.
HTH!
And if you consider comments blank lines:
Although, that's language dependent.
It's kinda going to depend on the number of files you have in the project. In theory you could use
Where you can fill the list of files by using the find utility.
Would give you a line count per file.