计算单词出现在文件中的次数

时间:2022-08-17 15:43:48

What is an easy way to count the number of times a word appears in a file?

什么是计算单词出现在文件中的次数的简单方法?

3 个解决方案

#1


81  

This will also count multiple occurrences of the word in a single line:

这也会计算单行中多次出现的单词:

grep -o 'word' filename | wc -l

#2


2  

cat filename | tr ' ' '\n' | grep 'word' | wc -l

#3


-1  

fgrep "word to be counted" filename|wc -w

#1


81  

This will also count multiple occurrences of the word in a single line:

这也会计算单行中多次出现的单词:

grep -o 'word' filename | wc -l

#2


2  

cat filename | tr ' ' '\n' | grep 'word' | wc -l

#3


-1  

fgrep "word to be counted" filename|wc -w