首页 > 学院 > 操作系统 > 正文

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

2024-06-28 13:25:12
字体:
来源:转载
供稿:网友
一个用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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表