0

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>

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

May be worth mentioning to limit trimming from the right to '.' followed by digits only, you can use ${v%.[[:digit:]]*}. What you have is fine in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.