Home > Enterprise >  Grep all number from end of string upto any other char?, and save both parts to variables?
Grep all number from end of string upto any other char?, and save both parts to variables?

Time:04-30

I am trying grep only the numbers from the end of the string until any other char, so from example: "Version 1.2.34" Will give me '34' to variable $minor and 'Version 1.2.' to variable $type

I manage to

minor=$(grep -Eo '[0-9]{1,24}')

but this gives me ALL numbers.

CodePudding user response:

Using pure bash:

s="Version 1.2.34"

minor="${s##*[!0-9]}"
type="${s%$minor}"

declare -p type minor
declare -- type="Version 1.2."
declare -- minor="34"
  • Related