Home > Enterprise >  Extracting String from another string in shell
Extracting String from another string in shell

Time:02-22

I have string this:

release/3.0.2.344

And I want to extract this:

release/3.0.2

pattern is like:

release/<number>.<number>.<number>.<number>

CodePudding user response:

Use parameter expansion in bash:

$ v="release/3.0.2.344"

$ echo "${v%.*}"
release/3.0.2

% cuts off of the end of the variable, and the search pattern is a dot . followed by any characters *.

  • Related