Splitting a string in a bash script
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
Split string based on delimiter in bash?
我有一堆叫
根据本可以在bash版本:工作太
1 2 3 4 | test=test1.1024.out if [[ $test =~ ^test[A-Za-z0-9]+\.([0-9]+)\.out$ ]]; then echo ${BASH_REMATCH[1]} fi |
1 | sed -r 's/^test[[:alnum:]]*\.([[:digit:]]+)\.out$/\1/' |
也(a的短版本的bash for循环):
1 | awk -F '.' '{print $2}' |
1 2 3 4 5 | for f in test*.out; do number=${f#test*.} number=${number%.*} echo $f has middle number $number done |