1. 程式人生 > >shell學習(四)

shell學習(四)

分隔 編號 nbsp 長度 shell 位置 str bsp entos

一、字符截取

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

shell學習(四)