If the positions are fixed, you can use Bash's substring parameter expansion:
A="ABCDE"; echo ${A:1:2}
This prints BC
. You can use this for example in a for A in *; do
loop:
for A in *.M; do NUMID=${A:4:4} echo "We extracted \"${NUMID}\" from \"${A}\"."done