Shell中求字符串中单词的个数的几种方法 方法一: [linux@host ~]# echo 'one two three four five' | wc -w 5 方法二: [linux@host ~]#
Shell中求字符串中单词的个数的几种方法
方法一:
[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 AUnQoNa~]# 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
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对我们的支持。如果你想了解更多相关内容请查看下面相关链接
--结束END--
本文标题: Shell中统计字符串中单词的个数的几种方法
本文链接: https://www.lsjlt.com/news/20137.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0