题解 | #统计每个单词出现的个数#
统计每个单词出现的个数
https://www.nowcoder.com/practice/ad921ccc0ba041ea93e9fb40bb0f2786
#!/bin/bash declare -A wordCount while IFS=' ' read -r -a words do for word in "${words[@]}" do #关联数组保存单词和对应个数 ((wordCount[$word]++)) done done < nowcoder.txt for word in "${!wordCount[@]}" do #打印单词和个数 echo "$word ${wordCount[$word]}" #将输出的内容按照单词词频按升序排列 done | sort -k2n exit 0