#!/bin/bash if [ $# -ne 1 ] then echo "Usage: $0 filename"; exit -1 fi filename=$1 egrep -o "[[:alpha:]]+" $filename | awk '{ count[$0]++ } END{ printf("%-14s%s ", "word", "count"); for(ind in count) { printf("%-14s%d ", ind, count[ind]); } }'
egrep -o "[[:alpha:]]+" $filename 可以得到文件中所有的单词 为单词边界标记符