shell相关统计

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



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
    A+
发布日期:2021年08月03日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: