shell命令统计文件夹下有多少.ts结尾的文件

一、完整命令

实现目的:统计某文件夹下,以.ts结尾的文件有多少行(去注释去空行)

find . -name "*.ts" | grep './node_modules/' -v |xargs cat|sed 's/ //g'|egrep -v -e "^$" -e "^//" -e "^/\*" -e "^\*"|wc -l

二、逐步解析

1.查找当前文件夹下所有以.ts结尾的文件

find . -name "*.ts" | more

2.去掉其中的node_modules

find . -name "*.ts"  |grep './node_modules/' -v | more 

3.统计每个文件中的行数之和

find . -name "*.ts" | grep './node_modules/' -v |xargs cat|wc -l

 find . -name "*.ts" | grep './node_modules/' -v |xargs cat|more

4.去掉空行

find . -name "*.ts" | grep './node_modules/' -v |xargs cat|egrep -v -e "^$" |more

5.去掉注释

注释是去掉每行前面多余空格后,以/* 、*、 */、// 开头的行

find . -name "*.ts" | grep './node_modules/' -v |xargs cat|sed 's/ //g'|egrep -v -e "^$" -e "^//" -e "^/\*" -e "^\*"|wc -l

蓝色:去掉前面多余空格

绿色:以 // 开头

粉色:以 /* 开头

紫色:以 * 开头(包括了 */ 开头)

tips

 如果还不清楚或者想交个朋友的同学可以微信联系我:qq981145483(备注:csdn shell)

发布了57 篇原创文章 · 获赞 5 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_33807889/article/details/104274965