一个用shell写的统计目录下统计文件行数的代码

王朝学院·作者佚名  2016-05-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

一个用shell写的统计目录下统计文件行数的代码此代码是用来回忆当初学的shell脚本,很多知识忘了,写这个花了我三个小时的时间

#!/bin/ksh

#count *.c file the num of lineg_csum=0g_hsum=0

count(){# echo "$1,count_line" file_name="$1" res_line=`wc -l $file_name | awk '{PRint $1}'` echo $res_line return# find . -name "*.c" | xargs cat | wc -l}

statistics(){ echo "program start running" cur_line=0 echo $1# g_sum=`count $1` if test -f $1

then cur_line=`count $1` if [ "${1##*.}" = "c" ] then g_csum=$(($g_csum+$cur_line)) elif [ "${1##*.}" = "h" ] then g_hsum=$(($g_hsum+$cur_line)) fi echo $cur_line elif [ -d $1 ] then for file in $1/* do statistics $file done fi echo "g_csum" $g_csum echo "g_hsum" $g_hsum}

for file in $1

do statistics $1done

exit 0

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航