Given a filename in the form someletters_12345_moreleters.ext, I want to extract the 5 digits and put them into a variable.
someletters_12345_moreleters.ext
So to emphasize the point, I
I'm surprised this pure bash solution didn't come up:
a="someletters_12345_moreleters.ext" IFS="_" set $a echo $2 # prints 12345
You probably want to reset IFS to what value it was before, or unset IFS afterwards!
unset IFS