TrEE TO OnE O

Just So So ...

shell 截取字符串

方法1

#!/bin/sh
 
string="This is a testing"
echo ${string:3}
echo ${string:3:9} 

输出

s is a testing
s is a te

方法2

echo “This is a testing” | cut -c1-11

输出

his is a t

其中-c1-11代表截取 1-11的字符

echo "This is a testing" | cut -d" " -f 1

截取由空格分割的第一个字符串,即 This

标签: shell


添加新评论