统计文件中单词出现的次数

#get the first file
filename=$1
grep -E -o "\b[[:alpha:]]+\b" $filename | awk ' { count[$0]++ } 
END{printf("%-20s%s\n","Word","Count");
for(word in count)
{printf("%-20s%s\n",word,count[word])}
}'

  

[root@centos6-test06 ~]# cat /root/kevin.txt
the world kevin is the
is world grace the kevin
art the kevin the is kevin

 

sh count.sh kevin.txt

posted @ 2023-10-29 00:28  樱圃  阅读(6)  评论(0编辑  收藏  举报