2011-10-25 128 views

回答

2
for f in test*.out; do 
    number=${f#test*.} 
    number=${number%.*} 
    echo $f has middle number $number 
done 
2
sed -r 's/^test[[:alnum:]]*\.([[:digit:]]+)\.out$/\1/' 

或者(更短的版本BASH for循環):

awk -F '.' '{print $2}' 
2

根據猛砸的版本,這可能是工作太:

test=test1.1024.out 
if [[ $test =~ ^test[A-Za-z0-9]+\.([0-9]+)\.out$ ]]; then 
     echo ${BASH_REMATCH[1]} 
fi