Shell中求字符串中單詞的個(gè)數(shù)的幾種方法
方法一:
[linux@host ~]# echo 'one two three four five' | wc -w5
方法二:
[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 -l5
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)武林網(wǎng)的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
新聞熱點(diǎn)
疑難解答
圖片精選