shell相关统计

发布时间:2021-08-03 22:12:31 阅读:1305次

 统计一句话每个字母出现的频率


tr求和
cat tr.txt 
1 2 3 4 5 6 7 8 9 10
root@test:/home/test# cat tr.txt |echo $[$(tr '\n' '+') 0] 
55 
 
判断文件中每个单词出现的频率  
1 #!/bin/bash
  2 if [ $# -ne 1 ] ;
  3 then
  4 echo "Usage:$0 filename";
  5 exit -1
  6 fi
  7 
  8 filename=$1
  9 egrep -o "\b[[:alpha:]]+\b" $filename | \
 10 awk '{count[$0]++}
 11 END{printf("%-14s%s\n","word","count");
 12 for(ind in count)
 13 {printf("%-14s%d\n",ind,count[ind]);}
 14 }'
 
统计文件夹中每个类型的文件有多少
  1 declare -A statarray;
  2 while read line;
  3 do
  4         ftype=`file -b "$line"`
  5         let statarray["$ftype"]++;
  6 done< <(find . -type f -print)
  7 echo ============file types and counts============
  8 for ftype in "${!statarray[@]}";
  9 do
 10         echo $ftype : ${statarray["$ftype"]}
 11 done

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:shell相关统计 出自老鄢博客 | 欢迎分享