统计文件行数的shell

来源:互联网 发布:怎么看淘宝开店日期 编辑:程序博客网 时间:2024/06/10 01:17
#!/bin/bash#Program:#Count every cpp file and h file is line in a path ,and add them ,output it#History:# Build by AstrayLinux in 2011/10/17if [ $# -ge 1 ] ; then i=0;s=0;t=0;if [ -d $1 ] ; thenpath=$1shiftelsepath="./"fi while [ "$i" != "$#" ]dostr="\"*.$1\":  " echo "======================= *.$1 ========================="find $path -type f -name "*.$1" -exec wc -l {} \;t=`find $path -type f -name "*.$1" -exec cat {} \; |wc -l`echo "====================== *.$1 SUM ======================"printf "%11s %10d\n" $str $ts=$(( $s+$t ))shiftdoneecho "===================== ALL SUM ======================="printf "%11s %10d\n" "The all:" $selseecho "" echo "countSrcLine [path] [filetype ...]"echo "If path is empty ,it will be ./"echo "Filetype is a postfix like cpp,log. etc."echo "EXAMPLE: "echo  "countSrcLine ~/workspace/ cpp h"echo ""fiexit 0


结果如下


原创粉丝点击