统计file文件中单词good的个数,linuxjishu/13830.html target=_blank class=infotextkey>awk、sed与tr命令分别实现:
1、awk 'BEGIN {num=0} {i=1;while(i<=NF) {if ($i=="good") num++; i++}} END{ print "num="num}' sed
2、awk -v RS='<good>' 'END {print --NR}' file
3、sed 's/[^a-zA-Z]/n/g' file |sort |uniq -c |grep good
4、tr -s "t| " "n" <file |sort |uniq -c |grep good
5、sed 's/t/n/g;s/ /n/g' file |sort |uniq -c |grep good