统计words.txt中每个单词出现的次数并排序
解法1:
cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -r | awk '{print $2,$1}'
解法2:
cat words.txt | awk '{for(i=1;i<=NF;i++){count[$i]++}}END{for (i in count){print i,count[i]}}' | sort -k2nr
2024-01-31 10:43:46
统计words.txt中每个单词出现的次数并排序
解法1:
cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -r | awk '{print $2,$1}'
解法2:
cat words.txt | awk '{for(i=1;i<=NF;i++){count[$i]++}}END{for (i in count){print i,count[i]}}' | sort -k2nr