extract string from string

Hi there,

I'll need some help with a string extraction.
My main string is a filename let's say:
sdgfj ghjsdgfjhds11.xml
I'd like to extract 5 characters before file extension, in above case this would be
hds11

Can someone please help? I'd like to have this done in bash

# echo "sdgfj ghjsdgfjhds11.xml" | sed 's/.*\(.....\)\..*/\1/'
hds11
t=${a%?????.xml};b=${a##$t};echo "${b%%.*}"
# a="sdgfj ghjsdgfjhds11.xml"
# echo $a
sdgfj ghjsdgfjhds11.xml
# t=${a%?????.xml};b=${a##$t};echo "${b%%.*}"
hds11

or

# b=${a%%.*} ; t=${b%?????} ; echo ${b##$t}
hds11

wow, 10 minutes after i post my question and i already have the perfect solution... this is the best forum ever! :b:

ty ctsgnb!

Nice to see you got it working ! :slight_smile: