一,测试环境

echo "To the world you may be one person but to one person you may be the world"

对于世界而言,你是一个人;但是对于某个人,你是他的整个世界

二 , 解

  01,数组

     判断一段里面小于4的字符串

#!/bin/bash
#################################################
# File Name: arrs01.sh
# Author: kingle
# Mail: kingle_work@163.com
# Function:
# Created Time: 2018年11月06日 星期二 16时13分16秒
#################################################
array=(To the world you may be one person but to one person you may be the world)
for word in ${array[@]}
do
if [ ${#word} -lt 4 ]
then
echo ${word}
fi
done

      操作结果  

[root@kingle conpa]# sh arrs01.sh
To
the
you
may
be
one
but
to
one
you
may
be
the

  02,数组

      实现代码

#!/bin/bash
#################################################
# File Name: arrs01.sh
# Author: kingle
# Mail: kingle_work@163.com
# Function:
# Created Time: 2018年11月06日 星期二 16时13分16秒
#################################################
array=(To the world you may be one person but to one person you may be the world)
for ((i=;i<${#array[@]};i++))
do
if [ ${#array[i]} -lt 4 ]
then
echo ${array[i]}
fi
done

      操作结果     

[root@kingle conpa]# sh arrs02.sh
To
the
you
may
be
one
but
to
one
you
may
be
the

    

   03,awk  

[root@kingle conpa]# echo "To the world you may be one person but to one person you may be the world"|awk '{for(i=1;i<=NF;i++)if(length($i)<4)print $i}'
To
the
you
may
be
one
but
to
one
you
may
be
the

   04,awk

[root@kingle conpa]# echo "To the world you may be one person but to one person you may be the world"|xargs -n1|awk '{if(length($1)<4)print $1}'
To
the
you
may
be
one
but
to
one
you
may
be
the

   05.awk

      

[root@kingle conpa]# echo "To the world you may be one person but to one person you may be the world"|awk '{for(i=1;i<=NF;i++)if(length($i)<4)print $i;else print "yes"}'
To
the
yes
you
may
be
one
yes
but
to
one
yes
you
may
be
the
yes

  

        

shell 对字符的求长的更多相关文章

  1. Shell编写字符菜单管理-8

    第8章 Shell编写字符菜单管理 一.shell函数定义function menu(){ echo 'this is a func!!';} 二.shell函数使用menu 三.cat命令的here ...

  2. shell 关于字符切割 cut

    shell中运用于字符切割的是cut 其中 参数分别代表得意义是: -d :后面接分隔字符,将一段信息分割为数段,与 -f 一起使用 -f :将-d分割出来的数段 用 -f 取出第几段的意思 -c : ...

  3. shell 终端字符颜色

    终端的字符颜色是用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关,shell,python,perl等均可以调用. 转义序列是以 ESC 开头,可以用 \033 完成相同的工作(ESC ...

  4. Shell脚本字符串匹配及日常命令工具 - 用法总结(技巧指南)

    Shell提供了很多字符串和文件处理的命令,如awk.expr.grep.sed等命令,还有文件的排序.合并和分割等一系列的操作命令.下面重点总结下Shell字符串处理.文本处理以及各类命令及函数用法 ...

  5. Linux学习 -- Shell编程 -- 字符处理命令

    sort排序命令 sort [选项] 文件名 -f 忽略大小m写 -n 按数值型,默认字符串型 -r 反向 -t 指定分隔符 -k n[,m] 指定字段范围,默认行尾 eg. sort -n -t & ...

  6. linux shell 随机字符生成单词

    #!/bin/sh #生成随机5个单词 filecount= wordcount= flag= #-lt -le -gt -ge -eq #while [ $f -lt $filecount ]; # ...

  7. Linux shell -查找字符(find,xargs,grep)

    在当前目录下查找含有jmxremote字符的文件 test@>find . -type f|xargs grep "jmxremote" . 当前目录 -type 查找文件类 ...

  8. shell 获取字符创长度&&识别当前使用的shell&&检查是否为超级用户

    1.获得字符串长度 可以使用下面的方法获得变量值得长度: length=${#value} 例如: [root@gameserver1 shell]# var=12345678 [root@games ...

  9. Linux学习 -- Shell编程 -- 字符截取命令

    cut字段提取命令 cut [选项] 文件名 -f 列号: -d 分隔符: 局限性:空格为分隔符时不适用 printf命令 printf '输出类型输出格式' 输出内容 %s, %i, %f \a, ...

随机推荐

  1. SQL Server乱码处理(ASCII)

    CREATE FUNCTION [dbo].[RegexReplace] ( @string VARCHAR(MAX), --被替换的字符串 @pattern VARCHAR(255), --替换模板 ...

  2. raiden_graph

    使用mermaid描述 raiden 通道 AB,正常状态 graph LR A-- 60,100,S_100 ---B 通道 AB closed graph LR A((A)) -. 60,100 ...

  3. 以太坊系列之十七: 使用web3进行合约部署调用以及监听

    以太坊系列之十七: 使用web3进行智能合约的部署调用以及监听事件(Event) 上一篇介绍了使用golang进行智能合约的部署以及调用,但是使用go语言最大的一个问题是没法持续监听事件的发生. 比如 ...

  4. NSSet集合

    前言 NSSet:集合 NSSet 集合跟数组差不多,但 Set 集合不能存放相同的对象,它是一组单值对象的集合,被存放进集合中的数据是无序的,它可以是可变的,也可以是不变的. Xcode 7 对系统 ...

  5. Mysql初识数据库《一》下载安装Mysql

    #1.下载:MySQL Community Server 5.7.16 http://dev.mysql.com/downloads/mysql/ #2.解压 如果想要让MySQL安装在指定目录,那么 ...

  6. 在CentOS-6.3环境下,利用grub工具手工制作Linux U盘安装盘

    注:此文是本人亲自操作实现后写的心得,同时也是对自己操作的记录. 制作的全过程概况 准备工作: U盘重新分区: 格式化U盘: 安装grub文件到U盘特定的分区: 拷贝镜像中的相关文件到U盘: 安装时设 ...

  7. SDUT OJ 数据结构实验之排序一:一趟快排

    数据结构实验之排序一:一趟快排 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...

  8. Hadoop Hive概念学习系列之什么是Hive?

    参考  <Hadoop大数据分析与挖掘实战>的在线电子书阅读                   http://yuedu.baidu.com/ebook/d128cf8e33687e21 ...

  9. copy模拟

    1.copy是浅复制,只复制一层:而deepcopy是所有层都复制,适用于lis嵌套listt的复制.两都均是函数.

  10. C++_类和动态内存分配6-复习各种技术及队列模拟

    知识点: 队列:是一种抽象的数据类型(Abstract Data Type),可以存储有序的项目序列. 新项目被添加在队尾,并可以删除队首的项目.队列有些像栈.栈是在同一端进行添加和删除.这使得栈是一 ...