Kage Riyuu
Kage Riyuu

Reputation: 3

Extracting String from another string in shell

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>

Upvotes: 0

Views: 37

Answers (1)

pmf
pmf

Reputation: 36088

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 *.

Upvotes: 2

Related Questions