Open vieyahn2017 opened 4 years ago
var1=abc3559 #想要获得3559
操作:
var1_key=`echo $var1 | tr -cd "[0-9]"`
tr --help Usage: tr [OPTION]... SET1 [SET2] Translate, squeeze, and/or delete characters from standard input, writing to standard output.
-c, -C, --complement use the complement of SET1 -d, --delete delete characters in SET1, do not translate -s, --squeeze-repeats replace each sequence of a repeated character that is listed in the last specified SET, with a single occurrence of that character -t, --truncate-set1 first truncate SET1 to length of SET2 --help display this help and exit --version output version information and exit
var2=efg010B0C0 #efg是固定字符串,想要获得010B0C0
操作:
var2_key=echo $var2 | sed 's/sdk//g'
var2_key=echo $var2 | tr -d "sdk"
-c 使用指定内容的补集 -d 删除字符 -s 压缩字符 -t 截断字符
shell 字符串匹配变量(只取数字或者取固定字符串)
https://www.cnblogs.com/ivyharding/p/11227245.html