Get a number
In your specific example (when you have only one substring having only numbers):
echo ${f//[^0-9]/}
or
echo ${f//[^[:digit:]]/}
Get string between prefix and suffix
But if you want to specify the suffix and prefix of this line, you have the following alternative:
echo `basename ${f/num} .txt`
because it echo ${f/num%.txt}doesnβt work correctly, and Bash does not allow you to run something like echo ${${f/num}%.txt}.