shell学习(四)

一、字符截取

expr

基本用法

expr  substr   $var1   起始位置    截取长度,如:

[root@localhost mnt]# a=Centos6.9
[root@localhost mnt]#
[root@localhost mnt]# expr substr $a 1 6
Centos

cut

基本用法:

命令输出   |  cut  -c  起始位置-结束位置

命令输出   |  cut   -d  分隔符"  -f 字段编号

[root@localhost mnt]# a=Centos6.9
[root@localhost mnt]#
[root@localhost mnt]# expr substr $a 1 6
Centos

[root@localhost mnt]# echo $a
Centos6.9
[root@localhost mnt]# echo $a |cut -d 't' -f2
os6.9

 

posted @ 2018-04-20 17:00  凉生墨客  阅读(91)  评论(0编辑  收藏  举报