How to create a frequency list of every word in a file?

前端 未结 11 981
心在旅途
心在旅途 2020-12-04 09:59

I have a file like this:

This is a file with many words.
Some of the words appear more than once.
Some of the words only appear one time.

I

11条回答
  •  执念已碎
    2020-12-04 10:47

    If I have the following text in my file.txt.

    This is line number one
    This is Line Number Tow
    this is Line Number tow
    

    I can find the frequency of each word using the following cmd.

     cat file.txt | tr ' ' '\n' | sort | uniq -c
    

    output :

      3 is
      1 line
      2 Line
      1 number
      2 Number
      1 one
      1 this
      2 This
      1 tow
      1 Tow
    

提交回复
热议问题