统计一句话每个字母出现的频率
root@test:/home/test#output=`echo "asdfaadfs"|sed 's/[^\n]/&\n/g'|sed '/^$/d'|sort|uniq -c |tr -d '\n'` root@test:/home/test# echo $output3 a 2 d 2 f 2 s
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