Shell中取子串的方法


Shell中取子串的方法
 
1.简单常用的方法
$ expr substr "linuxsong" 1 5
linux
 
 
2.直接变量截取
$ a="linuxsong"
$ echo ${a:0:5}
linux
 
 
3.用cut截取字符串
$ echo "linuxsong" | cut -c 1-5 #取第1-5个字符
linux
 
 
4.awk取子串
$ echo "linuxsong" | awk '{print substr($0,1,5)}'
linux
 
 
5.head取子串
$ echo "linuxsong" | head -c5
linux
 
 
6.tail方法
 
 
7.sed方法
 
 
转换大小写用echo "hello" | tr '[a-z]' '[A-Z]'

相关内容

    暂无相关文章