echo DEN_ML2.3_R02.zip | grep -o '[0-9]\+'
Output:
2
3
02
我想从2.3
grep 02
和DEN_ML2.3_R02.zip
并分配给变量
答案 0 :(得分:1)
$ echo DEN_ML2.3_R02.zip | grep -Eo '\-?[0-9]+(\.[0-9]+)?'
_________ _
^ ^
group quantifier
量词?
表示该群组可选
2.3
02
$ read a1 a2 < <(echo $(grep -Eo '\-?[0-9]+(\.[0-9]+)?' <<< "DEN_ML2.3_R02.zip"))
或
$ read a1 a2 < <(
grep -Eo '\-[0-9]+(\.[0-9]+)?' <<< "DEN_ML2.3_R02.zip" |
tr '\n' ' '
)
$ echo $a1
2.3
$ echo $a2
02