shell脚本统计C/C++代码行
版权声明 本站原创文章 由 萌叔 发表
转载请注明 萌叔 | https://vearne.cc
#current directory
CURR_DIR='.'
if [ ! -z $1 ];then
CURR_DIR=$1
fi
# create 3 tempory file to record detail infomation
find $CURR_DIR -name "*.cpp" | xargs wc -l > cpp_line_detail.txt
find $CURR_DIR -name "*.c" | xargs wc -l > c_line_detail.txt
find $CURR_DIR -name "*.h" | xargs wc -l > h_line_detail.txt
#count
CPP_COUNT=$(tail -1 cpp_line_detail.txt | sed -e 's/^ *//' | sed -e 's/ .*$//')
C_COUNT=$(tail -1 c_line_detail.txt | sed -e 's/^ *//' | sed -e 's/ .*$//')
H_COUNT=$(tail -1 h_line_detail.txt | sed -e 's/^ *//' | sed -e 's/ .*$//')
echo "The code in *.cpp files is "$CPP_COUNT" lines"
echo "The code in *.c files is "$C_COUNT" lines"
echo "The code in *.h files is "$H_COUNT" lines"
echo "------------------------------------"
#the final result
echo "The total number of lines is "$(($CPP_COUNT + $C_COUNT + $H_COUNT))
后记
这是我2012年的文章