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
gives the count of non blank lines in the current working directory.
If you want to use something other than a shell script, try CLOC:
The above will give you the total count of lines of code (blank lines removed) for a project (current folder and all subfolders recursively).
In the above "./blog" "./punbb" "./js/3rdparty" and "./pma" are folders I blacklist as I didn't write the code in them. Also .php, .as, .sql, .css, .js are the extensions of the files being looked at. Any files with a different extension are ignored.
There's already a program for this on linux called 'wc'.
Just
and it gives you the total lines and the lines for each file.
Script to recursively count all non-blank lines with a certain file extension in the current directory:
Sample usage:
This command count number of non-blank lines in our project.
cat fileName | grep -v ^$ | wc -l
grep -v ^$ regular expression function is ignore blank lines.