Substring in string with whitespaces

hello,

i have this string:
variable="1234 /PARAMETER_1:text /PARAMETER_2:othertext"

i tried to do
expr match $variable '.*\([TER_1:[a-z]*\)'

but i keep getting expr error

i need to extract the word text...

thank you

one way:

#  echo "1234 /PARAMETER_1:text /PARAMETER_2thertext" | sed 's/.*TER_1:\([a-z]*\).*/\1/'
text
1 Like

Thank you Tytalus!

updated.

variable="1234 /PARAMETER_1:text /PARAMETER_2:othertext"
echo $variable |awk -F":| " '{print $3}'

@rdcwayx

The "|" in the character class isn't use as an OR operator but as a fieldseparator:

awk -F"[ |:]"

The OR operator could be used like:

awk -F":| "
1 Like