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, ...
随机推荐
- UVa 10245 The Closest Pair Problem (分治)
题意:给定 n 个点,求最近两个点的距离. 析:直接求肯定要超时的,利用分治法,先把点分成两大类,答案要么在左边,要么在右边,要么一个点在左边一个点在右边,然后在左边或右边的好求,那么对于一个在左边一 ...
- 【C#】CLR内存那点事(string)
string是比特殊的类,说引用类型,但不存在堆里面,而且String str=new String("HelloWorld")这样的重装也说没有的. 我们先来看一个方法 clas ...
- 将“100px” 转换为100
parseInt("100px") //结果是100
- 来自网易云的黑科技,带尖角的div......
今天在网易云的网页版听歌,话说Steve Vai的曲子永远是这么让人揣摩不透,不过我还时更喜欢老Joe,咦,跑题了··· 大家可以看到评论输入框和回复框,上面都有个小尖角,实现的方式有很多,我一般是用 ...
- 浅谈 kubernetes service 那些事(上篇)
一.问题 首先,我们思考这样一个问题: 访问k8s集群中的pod, 客户端需要知道pod地址,需要感知pod的状态.那如何获取各个pod的地址?若某一node上的pod故障,客户端如何感知? 二.k8 ...
- shipyard
https://www.ivankrizsan.se/2016/07/10/managing-containers-shipyard/ kubernetes中文社区:https://www.kuber ...
- Kotlin 字符模板
Kotlin的字符模板和c语言的格式化输出有点像. 先来说说Kotlin 的字符模板怎么弄. fun main(args:Array<String>) { var name="T ...
- 如何解决diff: /../Podfile.lock: No such file or directory 的问题
1.问题描述 之前碰到过此类问题,原因是之前用了测试版本的pod,然后回归正式版本,导致找不到pod文件 diff: /../Podfile.lock: No such file or directo ...
- Atcoder Grand Contest 031B(DP,思维)
#include<bits/stdc++.h>using namespace std;int a[200007];int b[200007];long long dp[200007];lo ...
- golang并发练习代码笔记
golang语言的精髓就是它的并发机制,十分简单,并且极少数在语言层面实现并发机制的语言,golang被成为网络时代的c语言,golang的缔造者也有c语言的缔造者,Go语言是google 推出的一门 ...