Count the number of times a word appears in a file

后端 未结 3 450
一个人的身影
一个人的身影 2020-12-14 13:54

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

相关标签:
3条回答
  • 2020-12-14 14:21

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

    grep -o 'word' filename | wc -l
    
    0 讨论(0)
  • 2020-12-14 14:30
    cat filename | tr ' ' '\n' | grep 'word' | wc -l
    
    0 讨论(0)
  • 2020-12-14 14:36
    fgrep "word to be counted" filename|wc -w
    
    0 讨论(0)
提交回复
热议问题