shell编程--简单代码统计脚本
来源:互联网 发布:汕头哪里有培训淘宝 编辑:程序博客网 时间:2024/05/29 14:12
#!/bin/bashhelp(){ echo "usage : count.sh search_key search_date"}if [ $# -ne 2 ];then help exit 0else cd ~/source n=`grep -rn "$1" ./ | grep "$2"|wc -l` if [ $(($n%2)) -ne 0 ];then echo "source code tag not match" exit 0 fi sum1=`grep -rn "$1" ./ | grep "$2" | awk -F: 'BEGIN {i = 0; sum = 0}{if (NR%2 != 0){i = $2} else {odd = $2; sum += $2 - i + 1}} END {print sum}'` cd ~/include n=`grep -rn "$1" ./ | grep "$2"|wc -l` if [ $(($n%2)) != 0 ];then echo "include code tag not match" exit 0 fi sum2=`grep -rn "$1" ./ | grep "$2" | awk -F: 'BEGIN {i = 0; sum = 0}{if (NR%2 != 0){i = $2} else {odd = $2; sum += $2 - i + 1}} END {print sum}'` printf "code line count = %d\n" $(($sum1 + $sum2))fi
注意不同shell在语法上有差异,例子使用bash
1.在bash下 $(())可以简单计算字符串的算术运算
2.条件控制语句,注意下面的空格
if空格[空格expression空格];then
fi
if空格[空格expression空格];then
语句
else #注意else里最少要有一句,否则就不要用else
语句
fi
if空格[空格expression空格];then
语句
elif空格[空格expression空格];then
语句
else #注意else里最少要有一句,否则就不要用else
语句
fi
3.变量的赋值,等号两边不能有空格
4.printf 格式字符串 参数1 参数2 ...#注意中间的空格
5.awk中的NR,表示当前已经读取的记录数,从1开始,不是0
0 0
- shell编程--简单代码统计脚本
- 简单的shell脚本编程
- shell脚本编程简单实例
- 简单入门shell脚本编程
- 统计代码行数的shell脚本
- 利用shell脚本统计代码行数
- 一个简单统计时间间隔的shell脚本Demo
- 一个简单统计时间间隔的shell脚本Demo
- Linu Shell 编程基础--一个简单的Shell脚本
- shell脚本编程教程之二 --- 基本的shell编程格式+简单的脚本实例
- 简单shell统计单词
- Shell统计代码行数
- Shell统计代码行数
- shell统计代码行数
- 代码行统计脚本
- 代码量统计脚本
- 统计代码行数脚本
- shell脚本统计: netstat数据
- 获得树形json串
- 购物节来啦!!!!!!!!!!!
- 【android】进程优先级(Framework设置优先级,LowMemoryKiller查杀)
- ApiDemos – BouncingBalls分析
- 语音编码分类及编解码标准
- shell编程--简单代码统计脚本
- web.xml里<filter-mapping>中的<dispatcher>作用
- OCP规范中一个有趣的AVP REPORTING REASON
- 对Java程序员有益的十个网站
- 常见图片宽高解析
- 中国awe发哈温哥华awe分
- 一个spring的例子入门
- Swift 的函数式 API
- Android 弹出系统menu菜单