论坛首页 综合技术论坛

统计目录下C代码的总行数

浏览 4237 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-12-15   最后修改:2008-12-15
#!/bin/sh

#
# Line Counter
#
# Usage: lcnt dir suffix1, suffix2, suffix3 ...
#


v_dir="$1"
v_linenum=0

if [ $# = 0 ]; then
    echo "============================================="
    echo "Usage: lcnt dir suffix1 suffix2 suffix3 ...  "
    echo "Usage: lcnt dir                              "
    echo "============================================="
elif [ $# = 1 ]; then
    v_linenum=$(find $v_dir -type f | xargs -i cat {} | wc -l)
    echo "Total: "$v_linenum
else
    while [ "$2" != "" ]; do
        v_linenum=$(find $v_dir -type f -name "*$2" | xargs -i cat {} | wc -l)
        echo "*$2: "$v_linenum
        shift
    done
fi

exit 0

   发表时间:2008-12-15  
find . -type f -iname "*.c" -exec cat {} \; | grep -v '^$' | wc -l


一行shell命令搞定
0 请登录后投票
   发表时间:2008-12-15   最后修改:2008-12-15
0 请登录后投票
   发表时间:2008-12-15  
robbin的简洁强悍
0 请登录后投票
   发表时间:2008-12-24  
robbin 写道
find . -type f -iname "*.c" -exec cat {} \; | grep -v '^$' | wc -l


一行shell命令搞定


学习了
0 请登录后投票
   发表时间:2008-12-24  
-exec cat {}和直接|cat那个快?
另外grep -c也应该比grep |wc -l效率高一些
0 请登录后投票
   发表时间:2008-12-24   最后修改:2008-12-24
robbin 写道
find . -type f -iname "*.c" -exec cat {} \; | grep -v '^$' | wc -l


一行shell命令搞定

我经常
find . | grep ".c$" | xargs wc -l
还能看到每个文件多少行。。。
0 请登录后投票
论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics