十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
這篇文章給大家介紹如何在Shell中統(tǒng)計(jì)字符串中單詞的個(gè)數(shù),內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

方法一:
[linux@host ~]# echo 'one two three four five' | wc -w 5
方法二:
[linux@host ~]# echo 'one two three four five' | awk '{print NF}'
5方法三:
[linux@host ~]# s='one two three four five'
[linux@host ~]# set ${s}
[linux@host ~]# echo $#
5方法四:
[linux@host ~]# s='one two three four five'
[linux@host ~]# a=($s)
[linux@host ~]# echo ${#a[@]}
5方法五:
[linux@host ~]# s='one two three four five' [linux@host ~]# echo $s | tr ' ' '\n' | wc -l 5
關(guān)于如何在Shell中統(tǒng)計(jì)字符串中單詞的個(gè)數(shù)就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。