常用linux 命令 -字符串相关

参考网络文章,个人工作总结

题记:一般对字符串的操作有以下几种:求长度,截取字符串,拼接字符串,找字符串中某个字符的索引

1 expr 命令

1.1 定义

man 手册

 Print  the  value  of  EXPRESSION to standard output.  A blank line below separates increasing precedence
       groups.  EXPRESSION may be:

       ARG1 | ARG2
              ARG1 if it is neither null nor 0, otherwise ARG2

       ARG1 & ARG2
              ARG1 if neither argument is null or 0, otherwise 0

       ARG1 < ARG2
              ARG1 is less than ARG2
。。。等等
跟字符串相关的
  match STRING REGEXP
              same as STRING : REGEXP

       substr STRING POS LENGTH
              substring of STRING, POS counted from 1

       index STRING CHARS
              index in STRING where any CHARS is found, or 0

       length STRING
              length of STRING

1.2示例

[devtac@test_1 ~]$ expr length "how can i just let you walk away"
32

[devtac@test_1 ~]$ expr length "how "
4

 
  

[devtac@test_1 ~]$ expr substr "how can i just" 2 6
ow can
[devtac@test_1 ~]$ expr index "how can i how" h
1

 

 

转载于:https://www.cnblogs.com/tacg/p/4151063.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值