打印下面不大于6的单词

[root@shnne ~]# cat liu.log 
I am shnne welcome to my blog.

[root@shnne ~]# cat liu.sh 
#!/bin/sh
array=($(cat liu.log))
for((i=0;i<${#array[@]};i++))
do
  if [ ${#array[$i]} -le 6 ]
   then
      echo ${array[$i]}
  fi
done

echo "-------------"
#!/bin/sh
for i in `cat liu.log`
do
   if [ ${#i}  -le 6 ]
    then
     echo $i 
   fi
done

echo "-------------"

[root@shnne ~]# echo "I am shnne welcome to my blog."|awk '{for(i=0;i<=NF;i++) if(length($i)<=6) print $i }'


技术点:

对子串长度的判断

1.echo shnne|wc -L

2.变量子串${#shnne}

3.expr length "shnne"

4.awk


分享到:
关键词:Linux运维Shell

网友留言(0 条)

发表评论