统计基础
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
循环统计每个字母出现的次数
for i in {a..z};do
cat /etc/ssh/sshd_config |grep -o $i |wc -l
done
把字母打印出来更加直观
for i in {a..z};do
countresult=$(cat /etc/ssh/sshd_config |grep -o $i | wc -l)
echo -e "$i\t$countresult"
done
统计大写字母
for i in {A..Z};do
result=`cat /etc/ssh/sshd_config |grep -o $i |wc -l`
echo -e "$i\t$result"
done
统计每个数字
for i in {0..9};do
result=`cat /etc/ssh/sshd_config |grep -o $i |wc -l`
echo -e "$i\t$result"
done
统计每个字母、每个数字出现的次数
for i in {0..9} {a..z} {A..Z};do
countresult=$(cat /etc/ssh/sshd_config |grep -o $i | wc -l)
echo -e "$i\t$countresult"
done
注意如果统计到正则字符需要加反斜杠\
cat /etc/ssh/sshd_config |grep --color '\.'