I have a shell variable with a string like the following "PA-232 message1 GX-1234 message2 PER-10 message3"
I need to apply a regular expression that detects PA-232, GX-1234 and PER-10 and returns these ocurrences.
How can I do this in bash?
I've tried this:
echo "PA-232 message1 GX-1234 message2 PER-10 message3" | sed -r 's/^.*([A-Z]+-[0-9]+).*$/\1/'
But it returns
R-10
instead of
PA-232
GX-1234
PER-10