shell 对字符的求长
一,测试环境
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 对字符的求长的更多相关文章
- Shell编写字符菜单管理-8
第8章 Shell编写字符菜单管理 一.shell函数定义function menu(){ echo 'this is a func!!';} 二.shell函数使用menu 三.cat命令的here ...
- shell 关于字符切割 cut
shell中运用于字符切割的是cut 其中 参数分别代表得意义是: -d :后面接分隔字符,将一段信息分割为数段,与 -f 一起使用 -f :将-d分割出来的数段 用 -f 取出第几段的意思 -c : ...
- shell 终端字符颜色
终端的字符颜色是用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关,shell,python,perl等均可以调用. 转义序列是以 ESC 开头,可以用 \033 完成相同的工作(ESC ...
- Shell脚本字符串匹配及日常命令工具 - 用法总结(技巧指南)
Shell提供了很多字符串和文件处理的命令,如awk.expr.grep.sed等命令,还有文件的排序.合并和分割等一系列的操作命令.下面重点总结下Shell字符串处理.文本处理以及各类命令及函数用法 ...
- Linux学习 -- Shell编程 -- 字符处理命令
sort排序命令 sort [选项] 文件名 -f 忽略大小m写 -n 按数值型,默认字符串型 -r 反向 -t 指定分隔符 -k n[,m] 指定字段范围,默认行尾 eg. sort -n -t & ...
- linux shell 随机字符生成单词
#!/bin/sh #生成随机5个单词 filecount= wordcount= flag= #-lt -le -gt -ge -eq #while [ $f -lt $filecount ]; # ...
- Linux shell -查找字符(find,xargs,grep)
在当前目录下查找含有jmxremote字符的文件 test@>find . -type f|xargs grep "jmxremote" . 当前目录 -type 查找文件类 ...
- shell 获取字符创长度&&识别当前使用的shell&&检查是否为超级用户
1.获得字符串长度 可以使用下面的方法获得变量值得长度: length=${#value} 例如: [root@gameserver1 shell]# var=12345678 [root@games ...
- Linux学习 -- Shell编程 -- 字符截取命令
cut字段提取命令 cut [选项] 文件名 -f 列号: -d 分隔符: 局限性:空格为分隔符时不适用 printf命令 printf '输出类型输出格式' 输出内容 %s, %i, %f \a, ...
随机推荐
- phpmyadmin安全预防
头疼的安全 之前服务器总是本人黑,千疮百孔,只能一步步的去做一些安全防范,如何防范自然先从如何渗透开始. 文章及建议 前段时间看到了个phpmyadmin提权的教程,很多人都说现在那里还有root帐号 ...
- 让IE播放PPT
在win7下安装office 2003,想让ppt在ie里播放,然后供winform调用,显示并播放ppt,操作如下 HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Power ...
- HtmlAgilityPack 使用
或.无属性.属性个数.属性值: var preceding_siblings = node.SelectNodes("preceding-sibling::input| preceding- ...
- Java以邮件附件的方式发送excel文件
String to = "xxx@qq.com"; // 收件人的QQ邮箱 String from = "xxx@qq.com"; // 发件人的QQ邮箱 St ...
- kali linux之服务扫描
识别开放端口上运行的应用.识别目标操作系统,提高攻击效率 banner捕获(软件开发商,软件名称,服务类型,版本号-----直接发现已知的漏洞和弱点) 服务识别 操作系统识别 snmp分析(简单网络管 ...
- 如何理解<base href="<%=basePath%>" ---转载
原文链接http://316325524.blog.163.com/blog/static/6652052320111118111620897/ "base href " 今天在写 ...
- 安装 CentOs 系统 及 Python 及 Scrapy 框架
1: 先安装Centos 系统: 为什么选择CentOs系统,而不选择Ubuntu ? 我在Ubuntu上尝试了三次安装 python 和 Scrapy ,结果都没成功,在运维老王的建议下 使用Cen ...
- python连接postgreSQL
利用python(我用的是python2.7版本)连接postgresql数据库,这里使用psycopg2这个插件 官网下载psycopg2-2.5.1.tar.gz:http://initd.org ...
- 自旋锁Spin lock与互斥锁Mutex的区别
POSIX threads(简称Pthreads)是在多核平台上进行并行编程的一套常用的API.线程同步(Thread Synchronization)是并行编程中非常重要的通讯手段,其中最典型的应用 ...
- JUC包下Semaphore学习笔记
在Java的并发包中,Semaphore类表示信号量.Semaphore内部主要通过AQS(AbstractQueuedSynchronizer)实现线程的管理.Semaphore有两个构造函数,参数 ...