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