天天看点

shell编程——统计各个字符出现的次数

统计基础

cat /etc/ssh/sshd_config |grep -o a

cat /etc/ssh/sshd_config |grep -o b

使用{a..z}可以循环获取26个小写字母

for i in {a..z};do

  echo "read it $i"

done

循环统计每个字母出现的次数

  cat /etc/ssh/sshd_config |grep -o $i |wc -l

把字母打印出来更加直观

  countresult=$(cat /etc/ssh/sshd_config  |grep -o $i | wc -l)

  echo -e "$i\t$countresult"

统计大写字母

for i in {A..Z};do

  result=`cat /etc/ssh/sshd_config |grep -o $i |wc -l`

  echo -e "$i\t$result"

统计每个数字

for i in {0..9};do

统计每个字母、每个数字出现的次数

for i in {0..9} {a..z} {A..Z};do

继续阅读