Shell脚本统计文件行数
Shell脚本统计文件行数
awk '{print NR}' row_count.sh | tail -n1 awk 'END{print NR}' row_count.sh grep -n "" row_count.sh|awk -F: '{print '} | tail -n1 sed -n '$=' row_count.sh wc -l row_count.sh cat row_count.sh | wc -l
一、获取指定目录所有文件的行数:
#!/bin/bash filesCount=
linesCount=
function funCount()
{
for file in ` ls $ `
do
if [ -d $"/"$file ];then
funCount $"/"$file
else
declare -i fileLines
fileLines=`sed -n '$=' $"/"$file`
let linesCount=$linesCount+$fileLines
let filesCount=$filesCount+
fi
done
} if [ $# -gt ];then
for m_dir in $@
do
funCount $m_dir
done
else
funCount "."
fi
echo "filesCount = $filesCount"
echo "linesCount = $linesCount"
使用方法:
1、针对本目录
./count.sh
2、统计多个目录
./count.sh /tmp ~
二、获取指定目录特定扩展名文件的行数
#!/bin/bash
extens=(".c" ".cpp" ".h" ".hpp")
filesCount=
linesCount=
function funCount()
{
for file in ` ls $ `
do
if [ -d $"/"$file ];then
funCount $"/"$file
else
fileName=$"/"$file EXTENSION="."${fileName##*.}
echo "fileName = $fileName Extension = $EXTENSION" if [[ "${extens[@]/$EXTENSION/}" != "${extens[@]}" ]];then
declare -i fileLines
fileLines=`sed -n '$=' $fileName`
echo $fileName" : "$fileLines
let linesCount=$linesCount+$fileLines
let filesCount=$filesCount+
fi
fi
done
} if [ $# -gt ];then
for m_dir in $@
do
funCount $m_dir
done
else
funCount "."
fi
echo "filesCount = $filesCount"
echo "linesCount = $linesCount"
使用方法:
1、针对本目录
./count.sh
2、统计多个目录
./count.sh /tmp ~
Shell脚本统计文件行数的更多相关文章
- 一个用shell写的统计目录下统计文件行数的代码
此代码是用来回忆当初学的shell脚本,很多知识忘了,写这个花了我三个小时的时间 #!/bin/ksh #count *.c file the num of lineg_csum=0g_hsum=0 ...
- Linux - wc统计文件行数、单词数或字节数
一 wc简单介绍 wc命令用来打印文件的文本行数.单词数.字节数等(print the number of newlines, words, and bytes in files).在Windows的 ...
- Linux统计文件行数
语法:wc [选项] 文件… 说明:该命令统计给定文件中的字节数.字数.行数.如果没有给出文件名,则从标准输入读取.wc同时也给出所有指定文件的总统计数.字是由空格字符区分开的最大字符串. 该命令各选 ...
- wc命令--Linux统计文件行数
语法:wc [选项] 文件… 说明:该命令统计给定文件中的字节数.字数.行数.如果没有给出文件名,则从标准输入读取.wc同时也给出所有指定文件的总统计数.字是由空格字符区分开的最大字符串. 该命令各选 ...
- 利用shell脚本统计文件中出现次数最多的IP
比如有如下文件test.txt 1 134.102.173.43 2 134.102.173.43 3 134.102.171.42 4 134.102.170.9 要统计出现次数最多的IP可 ...
- linux 使用wc命令统计文件行数、字数及大小
语法:wc [选项] 文件… 说明:该命令统计给定文件中的字节数.字数.行数.如果没有给出文件名,则从标准输入读取.wc同时也给出所有指定文件的总统计数.字是由空格字符区分开的最大字符串. 该命令各选 ...
- Linux下wc命令统计文件行数/词数/字符数/最长行字符数
wc命令帮助 $ wc --help Usage: wc [OPTION]... [FILE]... or: wc [OPTION]... --files0-from=F Print newline, ...
- linux 脚本统计代码行数
由于实际需求,需要统计开源产品的代码行数,so,以下命令统计*.c的行数. .h,.java .同理 find . -name *.c|xargs wc -l
- 统计文件行数,推荐使用LineNumberReader
一.主题: 读取文本文件最大行数性能比较:lineNumberReader > Files.lines 二.code 1 @Test 2 public void testLineReader() ...
随机推荐
- linux安装windows启动盘
安装gparted
- Python Learning: 03
An inch is worth a pound of gold, an inch of gold is hard to buy an inch of time. Slice When the sca ...
- selenium之元素定位-xpath
被测试网页的HTML代码 <html> <body> <div id="div1" style="text-align:center&quo ...
- 基于GPS数据建立隐式马尔可夫模型预测目的地
<Trip destination prediction based on multi-day GPS data>是一篇在2019年,由吉林交通大学团队发表在elsevier期刊上的一篇论 ...
- spring【一】 学习
Spring 源码学习 通过注解的形式注入IOC 简单的创建一个maven的项目的 下载指定的spring的核心jar包(https://mvnrepository.com/artifact/org. ...
- Vue.Draggable 文档总结
本文章转自https://blog.csdn.net/zjiang1994/article/details/79809687 Vue.Draggable学习总结 Draggable为基于Sortabl ...
- [认证授权] 1.OAuth2授权
1 OAuth2解决什么问题的? 举个栗子先.小明在QQ空间积攒了多年的照片,想挑选一些照片来打印出来.然后小明在找到一家提供在线打印并且包邮的网站(我们叫它PP吧(Print Photo缩写
- IdentityServer4实战 - JWT Issuer 详解
一.前言 本文为系列补坑之作,拖了许久决定先把坑填完. 下文演示所用代码采用的 IdentityServer4 版本为 2.3.0,由于时间推移可能以后的版本会有一些改动,请参考查看,文末附上Demo ...
- php密码对称encrypt加密
/** * 对用户的密码进行加密 * @param $password * @param $encrypt //传入加密串,在修改密码时做认证 * @return array/password */ ...
- java8 :: 用法 (JDK8 双冒号用法)
https://www.cnblogs.com/tietazhan/p/7486937.html