The number of lines of code statistics script

 

#!/bin/bash

# Statistics current folder (including subfolders) the number of effective lines of code under .sh script, not comments, and blank lines

# All lines
MY_LIST_VAR=`egrep -c -h -R --include="*.sh" ^.*$`
# The echo $ MY_VAR
MY_ALL_COUNT=0
# All blank lines
MY_LIST_SPACE_VAR=`egrep -c -h -R ^$ --include="*.sh"`
#echo $MY_LIST_SPACE_VAR
MY_ALL_SPACE_COUNT=0

# Comment lines
MY_LIST_COMMENT_VAR=`egrep -c -h -R "^#[^!]" --include="*.sh"`
#echo $MY_LIST_COMMENT_VAR
MY_ALL_COMMENT_COUNT=0

for loop in $MY_LIST_VAR 
do
    MY_ALL_COUNT=`expr $MY_ALL_COUNT + $loop`
done
for loop in $MY_LIST_SPACE_VAR 
do
    MY_ALL_SPACE_COUNT=`expr $MY_ALL_SPACE_COUNT + $loop`
done
for loop in $MY_LIST_COMMENT_VAR 
do
    MY_ALL_COMMENT_COUNT=`expr $MY_ALL_COMMENT_COUNT + $loop`
done
echo `expr $MY_ALL_COUNT -  $MY_ALL_COMMENT_COUNT - $MY_ALL_SPACE_COUNT`

 

Parameters Grep
 - C match line count output only.
- the I is not case sensitive (only applicable to single character).
- does not display the file name h query multiple files.
- Only the output file name containing the matching character when l query multiple files.
- n-rows and displaying the matched line number.
- S does not exist or does not display the error message text no match.
-v displays all lines do not contain matching text.

 

 

 

Guess you like

Origin www.cnblogs.com/xiangtingshen/p/12010322.html
Recommended