Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use the tr command to count the occurrence frequency of English words in linux

Shulou Source: shulou.com Published: 2022-06-01 11:01:53 10月03日 Update

This article mainly introduces how to use the tr command to count the frequency of English words in linux. It is very detailed and has a certain reference value. Interested friends must finish reading it!

Tr command we are very clear, you can delete the replacement, delete the string. In English, we often count the frequency of occurrence in English. If we use the conventional method, it is more troublesome to set up a calculator one by one. At this time, use the tr command to replace the space division with a newline character, and then use the tr command to delete the periods, commas and exclamation marks after some words. First take a look at the this.txt file to be replaced

The Zen of Python, by Tim Peters

Beautiful is better than ugly.

Explicit is better than implicit.

Simple is better than complex.

Complex is better than complicated.

Flat is better than nested.

Sparse is better than dense.

Readability counts.

Special cases aren't special enough to break the rules.

Although practicality beats purity.

Errors should never pass silently.

Unless explicitly silenced.

In the face of ambiguity, refuse the temptation to guess.

There should be one-- and preferably only one-- obvious way to do it.

Although that way may not be obvious at first unless you're Dutch.

Now is better than never.

Although never is often better than * right* now.

If the implementation is hard to explain, it's a bad idea.

If the implementation is easy to explain, it may be a good idea.

Namespaces are one honking great idea-let's do more of those!

For the above text file, if you want to count the top 10 words that appear in the text, you can use the following command

[root@linux ~] # cat this.txt | tr'\ n'| tr-d'[.,!]'| sort | uniq-c | sort-nr | head-1010 is8 better8 than5 to5 the3 of3 Although3 never3 be3 one is all the contents of the article "how to use the tr command to count the frequency of English words in linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Commands words English statistics frequency content documents articles face clear trouble value interest character string boy buddy regular meeting routine exclamation point Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Linux Microsoft Redmi Huawei