常用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