for file in *
do
[[ "$file" =~ [0-9]+ ]] && printf "%s\n" "${BASH_REMATCH[0]}"
done
From BASH manual:
BASH_REMATCH
An array variable whose members are assigned by the =~ binary operator to the [[ conditional command. The element with index 0 is the portion of the
string matching the entire regular expression. The element with index n is the portion of the string matching the nth parenthesized subexpression. This
variable is read-only.
If the files contain 1 extra digit (for instance a version number somewhere) then most of these methods will not render the correct results. You could select on the basis of how many digits need to be minimally present, for example 4:
IFS=_.
for file in *_*[0-9][0-9][0-9][0-9]*_*.*
do
set -- $file
for i do
case $i in (*[0-9][0-9][0-9][0-9]*)
printf "%d\n" "$i"
esac
done
done
IFS=$oldIFS
or
IFS=_.
for file in *_*[0-9][0-9][0-9][0-9]*_*.*
do
for i in $file
do
case $i in (*[0-9][0-9][0-9][0-9]*)
printf "%d\n" "$i"
esac
done
done
IFS=$oldIFS