通過單詞,我的意思是任何以空格分隔的字符串。在linux bourne shell中:如何統計文件中特定單詞的出現次數
假設該文件test.txt
具有由空格分隔以下的話:
hello hello hello hell osd
hello
hello
hello
hellojames beroo helloooohellool axnber hello
way
how
我想算的話你好出現在每一行的次數。
我使用的命令awk -F "hello" '{print NF-1}' test.txt
以顯示單詞出現的招呼中的每一行數:
3
1
1
1
4
0
0
所以發現總共3 + 1 + 1 + 1 + 4 = 10次出現。
問題是在第四行:你好只發生1次作爲單獨的單詞;文字如hellojames和helloooohellool不應該被計數,因爲你好不以空格分隔。
所以我想它找到7次出現你好作爲一個單獨的詞。
你能幫我寫一個返回正確總數7次的命令嗎?
你需要出現在數分離每一行,還是隻有總數? –
我只需要總共 – user1304473