shell脚本,按字母出现频率降序排序。
[root@localhost oldboy]# cat file the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support sections for more infomation [root@localhost oldboy]# cat 97.sh #!/bin/bash cat file| while read line do for i in `seq 1 ${#line}` do a=`echo $line|cut -c $i` echo "$a" >> zimu.txt done done cat zimu.txt|sed -r 's/[ \t]+//g'|grep -v ^$|sort|uniq -c |sort -nr [root@localhost oldboy]# bash 97.sh 19 s 17 e 16 o 14 t 12 n 12 i 11 r 9 a 8 u 7 p 7 d 6 m 4 l 4 c 3 f 2 q 2 h 2 b 1 w 1 v 1 P 1 j 1 g 1 . 1 , [root@localhost oldboy]#
[root@localhost oldboy]# cat file|awk 'BEGIN{FS=""}{for(i=1;i<=NF;i++){if($i!=" "){a[$i]++}}}END{for(i in a){print i,a[i]}}'|sort -nr -k 2 s 19 e 17 o 16 t 14 n 12 i 12 r 11 a 9 u 8 p 7 d 7 m 6 l 4 c 4 f 3 q 2 h 2 b 2 w 1 v 1 P 1 j 1 g 1 . 1 , 1 [root@localhost oldboy]#