I have a variable which holds the values like
Feature/ABC-12345-apple-orange-mango
bugfix/ABC-52364-orange-mango
story/ABC-42361-juice-grape-banana
I am looking for a command to extract the value ABC-[range of digits] only.
Using grep:
$ var='Feature/ABC-12345-apple-orange-mango
> bugfix/ABC-12345-apple-orange-mango
> story/ABC-12345-apple-orange-mango'
$ echo "$var" | grep -Eo 'ABC-[0-9]{5}'
ABC-12345
ABC-12345
ABC-12345
This will use grep with extended regex to search for any pattern that is ABC- followed by exactly 5 digits between 0-9. The -o flag will make grep print only the match.
ABC-12345a fixed string?...| grep -oP '[A-Z]{3}-[0-9]{5}'