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, ...
随机推荐
- 编译boost,去掉不使用的组件
说明:下面内容仅针对Linux环境(boost官网为:http://www.boost.org/,可从这里下载它的源代码包,这里要求下载.tar.gz包,而非.7z..zip或bz2包). 在当前目录 ...
- 编写高质量代码改善C#程序的157个建议——建议4: TryParse比Parse好
建议4: TryParse比Parse好 如果注意观察除string外的所有基元类型,会发现它们都有两个将字符串转型为本身的方法:Parse和TryParse.以类型double为例,这两个方法最简单 ...
- Matrix和Camera配合实现3D效果
一.Camera与Matrix简单介绍 1.Camera Android中一共有两个Camera,分别为:android.graphics.Camera android.hardware.Camera ...
- ASP.NET Session原理及处理方法
session是怎么存储,提取的 1.在服务器端有一个session池,用来存储每个用户提交session中的数据,Session对于每一个客户端(或者说浏览器实例)是“人手一份”,用户首次与Web服 ...
- Vue 编程式导航,路由history模式
import Vue from 'vue' import App from './App.vue' import Home from './components/Home.vue' import Ne ...
- SQL数据库查询语言(1)
目录 MySQL数据库 MySQL安装与配置 DDL数据定义语言 创建数据库 查看.删除数据库 修改.备份.恢复数据库 创建表 修改表 MySQL常用数据类型 DML数据操纵语言 Insert语句 m ...
- 移动端页面怎么适配ios页面
1.viewport 简单粗暴的方式:<meta name="viewport" content="width=320,maximum-scale=1.3,user ...
- Windows系统如何安装Redis?
转自 http://blog.csdn.net/lamp_yang_3533/article/details/52024744 一.Redis的下载地址 Redis官方并没有提供Redis的win ...
- django 实现电子支付功能
思路:调用第三方支付 API 接口实现支付功能.本来想用支付宝来实现第三方网站的支付功能的,但是在实际操作中发现支付宝没有 Python 接口,网上虽然有他人二次封装的的 Python 接口,但是对我 ...
- requests库和urllib包对比
python中有多种库可以用来处理http请求,比如python的原生库:urllib包.requests类库.urllib和urllib2是相互独立的模块,python3.0以上把urllib和ur ...