2017-09-21 74 views
1

所以,基本上我試圖計算每個單詞出現在廚師食譜文件上的出現次數。不正確的輸出uniq -c

7-zip 
ant 
ant 
ant 
apache2 
apache2 
apache2 
apache2 
api-example-v1 
api-products-v3 
apt 
apt 
apt 
ark 
ark 
ark 
artifactory 
artifactory 
artifactory-wrapper 
atp-cache-clear 

所以它應該是一樣簡單「的uniq -c myfile.txt的」(該文件已經排序),但我遇到的問題是,當我這樣做,我得到這樣的輸出:

1 7-zip 
2 ant 
1 ant 
3 apache2 
1 apache2 
1 api-example-v1 
1 api-products-v3 
2 apt 
1 apt 
2 ark 
1 ark 
1 artifactory 
1 artifactory 
1 artifactory-wrapper 
1 atp-cache-clear 
1 atp-cache-clear 
2 atpc-deployer 
1 atpc-deployer 
2 atpc-wrapper 
1 atpc-wrapper 

正如你所看到的輸出是不正確的。例如,「方舟」應該只出現一次,計數爲3.所有項目都是如此。

我已經做了這個沒有問題與另一個文件和輸出是正確的。

作爲一個說明,我已經嘗試過「cat -T myfile.txt」查看非打印字符,看看是否有什麼東西在那裏,我看不到但沒有顯示。

我還從文件的每一行中剝離了尾部和前導空格。

我還可能缺少什麼?

回答

5

cat -T只顯示標籤。使用cat -A顯示所有特殊字符。

+0

$ cat -A wholething.txt |頭-20 7-ZIP^M $ 螞蟻$ 螞蟻$ 螞蟻^ M $ 的Apache2 $ 的Apache2 $ 的Apache2 $ 的Apache2^M $ API的例子-V1^M $ API產品-V3^M $ 容易$ 容易$ 容易^ M $ 方舟$ 方舟$ 方舟^ M $ artifactory的$ artifactory的^ M $ artifactory的-包裝^ M $ ATP緩存清晰$ 什麼一個傻瓜!非常感謝,我現在可以看到發生了什麼。 –