【Linux】Shell - 字符串中插入字符



str="20171125"

$ echo ${str:0:4}-${str:4:2}-${str:6}

2017-11-25


取子串
* $ var="get length of me"
$ echo ${var:0:3}
get


$ echo ${var(-2)} #反方向
me


$ echo `expr substr "$var" 5 3`
the
$ echo $var | awk '{printf("%s\n",substr($0,5,6))}' #从第5个位置开始选取6个字符
length


* 使用cut取子串
$ echo $var | cut -d " " -f 4
me



参考文档:http://www.cnblogs.com/wangyuebo/p/6053006.html 

猜你喜欢

转载自blog.csdn.net/xunmengpiaoyun/article/details/78631128