這篇文章給大家介紹如何在Shell中統(tǒng)計字符串中單詞的個數(shù),內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
方法一:
[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)計字符串中單詞的個數(shù)就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
分享標(biāo)題:如何在Shell中統(tǒng)計字符串中單詞的個數(shù)-創(chuàng)新互聯(lián)
標(biāo)題鏈接:http://jinyejixie.com/article44/ghdhe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、響應(yīng)式網(wǎng)站、電子商務(wù)、品牌網(wǎng)站設(shè)計、小程序開發(fā)、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容