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
Use cut:
echo 'someletters_12345_moreleters.ext' | cut -d'_' -f 2
More generic:
INPUT='someletters_12345_moreleters.ext' SUBSTRING=$(echo $INPUT| cut -d'_' -f 2) echo $SUBSTRING