Try this:
echo "bob-type-8.2-mp2-2017-93-43-11-65-48.spr" | sed 's/^[^0-9]*//;s/\.[^.]*$//'
Output will:
8.2-mp2-2017-93-43-11-65-48
Explanation:
Sed uses pattern 's/pattern/replace_pattern/'
to find pattern
and replace it to replace_pattern
So, pattern 's/^[^0-9]*//'
get all symbols from start of line and before first digits occurance and replace it to nothing (replace_pattern
are empty).
The next step - delete extention. We can do this with the same sed's pattern 's///'
.
s/\.[^.]*$//
- find all symbols that not a .
at the end $
of line and replace it to nothing.
;
- devide patterns.
For best understanding you could use this command instead:
echo "bob-type-8.2-mp2-2017-93-43-11-65-48.spr" | sed -e 's/^[^0-9]*//' -e 's/\.[^.]*$//'