Shell中统计字符串中单词的个数的几种方法
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 ~]# 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
相关推荐
tianhuak 2020-11-24
huha 2020-10-16
lianshaohua 2020-09-23
laisean 2020-11-11
zhangjie 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
以梦为马不负韶华 2020-10-20
CARBON 2020-10-20
彼岸随笔 2020-10-20
lianshaohua 2020-10-20
yutou0 2020-10-17
JohnYork 2020-10-16
xiaonamylove 2020-10-16
Julyth 2020-10-16
applecarelte 2020-10-16
ourtimes 2020-10-16