請問cat讀取資料該如何統計分類呢? - Linux
By Ina
at 2009-10-27T22:53
at 2009-10-27T22:53
Table of Contents
請問各位版友 有辦法將cat讀取的資料做統計分類嗎?
例如有4個文字檔都只有一行 ( 1.txt 2.txt 3.txt 4.txt )
txt檔的內容可能在任何位置包含空白
1.txt的內容(沒有空白)
"ABC"
2.txt的內容(中間空白)
"A C"
3.txt的內容(前後空白)
" AB "
4.txt的內容(無內容無空白)
""
想取得類似下面的資訊
共有A,B,C 三個
A出現3次
B出現2次
C出現2次
請問用script該如何寫呢?
還請版友給個hint指點一下
我找到解答了
cat *.txt |tr '\n' ' '|sed 's/ //g'|sed 's/[^$]/&\n/g'|sort|uniq -c| sort -r
--
在平行的世界中,兩顆心跳是最遠的距離!
--
例如有4個文字檔都只有一行 ( 1.txt 2.txt 3.txt 4.txt )
txt檔的內容可能在任何位置包含空白
1.txt的內容(沒有空白)
"ABC"
2.txt的內容(中間空白)
"A C"
3.txt的內容(前後空白)
" AB "
4.txt的內容(無內容無空白)
""
想取得類似下面的資訊
共有A,B,C 三個
A出現3次
B出現2次
C出現2次
請問用script該如何寫呢?
還請版友給個hint指點一下
我找到解答了
cat *.txt |tr '\n' ' '|sed 's/ //g'|sed 's/[^$]/&\n/g'|sort|uniq -c| sort -r
--
在平行的世界中,兩顆心跳是最遠的距離!
--
Tags:
Linux
All Comments
By Charlotte
at 2009-10-28T05:33
at 2009-10-28T05:33
By Hedy
at 2009-11-02T05:22
at 2009-11-02T05:22
By Charlotte
at 2009-11-04T09:31
at 2009-11-04T09:31
By Rebecca
at 2009-11-07T16:47
at 2009-11-07T16:47
By Audriana
at 2009-11-10T15:05
at 2009-11-10T15:05
By Delia
at 2009-11-15T09:29
at 2009-11-15T09:29
By Rosalind
at 2009-11-16T19:09
at 2009-11-16T19:09
Related Posts
在圖書館推廣桌面版本的linux
By Frederica
at 2009-10-27T22:30
at 2009-10-27T22:30
關於桌面環境的問題
By Faithe
at 2009-10-27T18:18
at 2009-10-27T18:18
fc3如何自己連上線
By Suhail Hany
at 2009-10-27T18:09
at 2009-10-27T18:09
Sendmain無法寄信
By Ursula
at 2009-10-27T18:06
at 2009-10-27T18:06
g++版本問題
By Wallis
at 2009-10-27T18:00
at 2009-10-27T18:00