Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report