tr命令在統(tǒng)計(jì)英文單詞出現(xiàn)頻率中的妙用
tr命令我們很清楚,可以刪除替換,刪除字符串。 在英文中我們要經(jīng)常會(huì)經(jīng)常統(tǒng)計(jì)英文中出現(xiàn)的頻率,如果用常規(guī)的方法,用設(shè)定計(jì)算器一個(gè)個(gè)算比較費(fèi)事,這個(gè)時(shí)候使用tr命令,將空格分割替換為換行符,再用tr命令刪除掉有的單詞后面的點(diǎn)號(hào),逗號(hào),感嘆號(hào)。先看看要替換的this.txt文件
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!
上面的文本文件,如果要文中出現(xiàn)次數(shù)的最多的10個(gè)單詞統(tǒng)計(jì)出來(lái),可以使用下面的命令
[root@linux ~]# cat this.txt | tr ' ' '\n' | tr -d '[.,!]' | sort | uniq -c | sort -nr | head -10 10 is 8 better 8 than 5 to 5 the 3 of 3 Although 3 never 3 be 3 one
可謂非常方便!
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
- Linux刪除文件提示Operation not permitted的處理辦法
- Linux shell命令統(tǒng)計(jì)某列去重后的值
- Linux查看History記錄加時(shí)間戳的小技巧
- Linux后臺(tái)運(yùn)行Python程序的幾種方法講解
- Linux shell腳本的建立與執(zhí)行
- Python使用paramiko操作linux的方法講解
- Linux兩臺(tái)服務(wù)器之間傳輸文件和文件夾操作步驟
- Linux中文件/文件夾無(wú)法刪除的解決方案
- Android之在linux終端執(zhí)行shell腳本直接打印當(dāng)前運(yùn)行app的日志的實(shí)現(xiàn)方法
- Linux shell環(huán)境下Zabbix Api的使用
相關(guān)文章
apache,nginx上傳目錄無(wú)執(zhí)行權(quán)限的設(shè)置方法
至于為什么設(shè)置上傳目錄無(wú)權(quán)限這個(gè)我就不累贅了,現(xiàn)在比較流行的web服務(wù)有iis,apache,nginx,使用操作系統(tǒng)無(wú)非是windows or *nux2010-12-12改版時(shí)保留原鏈接,創(chuàng)建新的URL的方法
本功能的Alias指令在 httpd.conf中是這一句: #Alias /webpath /full/filesystem/path 去掉前面的#,并做下相應(yīng)的修改即可。2008-09-09Linux 使用init命令實(shí)現(xiàn)關(guān)機(jī),重啟,切換模式
這篇文章主要介紹了Linux 使用init命令實(shí)現(xiàn)關(guān)機(jī),重啟,切換模式的相關(guān)資料,需要的朋友可以參考下2017-03-03Linux文件服務(wù)器實(shí)戰(zhàn)詳解(匿名用戶)
這篇文章主要介紹了Linux文件服務(wù)器實(shí)戰(zhàn)(匿名用戶),非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-06-06Linux下安裝IPython配置python開發(fā)環(huán)境教程
這篇文章主要為大家詳細(xì)介紹了Linux下安裝IPython配置python開發(fā)環(huán)境教程,需要的朋友可以參考下2016-05-05Apache服務(wù)器中.htaccess的基本配置總結(jié)
這篇文章主要介紹了Apache服務(wù)器中.htaccess的基本配置總結(jié),可以很方便地實(shí)現(xiàn)一些權(quán)限分配等效果,需要的朋友可以參考下2015-07-07