Shell中求字符串中單詞的個數的幾種方法
方法一:
[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
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對武林網的支持。如果你想了解更多相關內容請查看下面相關鏈接
新聞熱點
疑難解答