#!/bin/bash if [ $# -ne 1 ] then echo "Usage: $0 filename"; exit -1 fi filename=$1 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为单词边界标记符
时间: 2024-11-07 04:28:11