每天一個shell腳本(17)統計文本中出現詞的數量並排序

需要統計文章:
eauty
Your lips your eyes your soul
Are like a work of art
The most creative thing of all
Is your beautiful heart
If you were a painting
No colours could express
The beauty deep inside you
A rainbow nothing less
If you were a sculpture
The clay could hardly make
Your figure of an angel
Without one mistake
If you were a euphony
No choir could really sing
All the beautiful music
Your eyes could possibly bring
So here I am an artist
With inspiration beyond belief
But to capture such rare beauty
I’d have to be a thief
Before I fall in love
my heart says we’ve got something real
can i trust the way i feel
cause my heart’s been fooled before
am i just seeing what I want to see
or is it true could you really be
somethone to have and hold
with my heart and soul
i need to know before i fall in love
someone who’ll stay around
through all my ups and downs
please tell me now before i fall in love
i’m at the point of on reture
so afraid of getting bumed
but i want to take a change
oh please give me a reason to believe
say that you’re the one that you’ll always be
it’s been so hard for me to give my heart away
but i would give my everything
just to here you say

#!/bin/bash
awk -F' ' '{for(i=0;i<NF;i++){print $i}}' ci | sort | uniq -c | sort -nr  | awk -F' ' '{printf("%s %s\n",$2,$1)}'

# awk
	-F:定義分隔符
	awk內使用for循環,NF代表的是當前擁有字段的總數()
# uniq
	-c:統計相同詞的次數
# sort
	-n:依照數字的大小排序
	-r:反向排序
# printf
	%s:string字符串
	$2,$1:輸出的位置變量結果

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章