1

I am using Jira to create a bitbucket branch for releases. As part of the build process I need to extract the release number from the branch name.

An earlier part of the build dumps the whole branch name to a text file. The problem I'm having is removing all the text before the build number.

An example branch name would be:

release/some-jira-ticket-343-X.X.X

Where X.X.X is the release number e.g. 1.11.1 (each of X could be any length integer).

My first thought was to literally just select the last 3 characters with sed, however as X could be any length this won't work.

Another post (Removing non-alphanumeric characters with sed) suggesting using the sed alpha class. However this won't work as the jira ticket ID will have numbers in.

Any ideas?

thewire247
  • 795
  • 1
  • 9
  • 24

4 Answers4

2

You can remove all characters up to last -:

$ sed 's/.*-//' <<< "release/some-jira-ticket-343-1.11.2"
1.11.2

or with grep, to output only digits and dots at the end of the line:

grep -o '[0-9.]*$'
SLePort
  • 15,211
  • 3
  • 34
  • 44
2

awk solution,

$ awk -F- '{print $NF}' <<< "release/some-jira-ticket-343-1.11.1"

grep solution,

grep -oP '[0-9]-\K.*' <<< "release/some-jira-ticket-343-1.11.1"
CWLiu
  • 3,913
  • 1
  • 10
  • 14
1

Awk solution:

awk -F [-.] '{ print $5"."$6"."$7 }' <<< "release/some-jira-ticket-343-12.4.7"

12.4.7

Set the field delimiter to - and . and then extract the pieces of data we need.

Raman Sailopal
  • 12,320
  • 2
  • 11
  • 18
1

use string operators:

var="release/some-jira-ticket-343-2.155.7"
echo ${var##*-}

print:

2.155.7
tso
  • 4,732
  • 2
  • 22
  • 32