Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the release value?

Tags:

regex

grep

sed

cut

I've a file with the below name formats:

rzp-QAQ_SA2-5.12.0.38-quality.zip
rzp-TEST-5.12.0.38-quality.zip
rzp-ASQ_TFC-5.12.0.38-quality.zip

I want the value as: 5.12.0.38-quality.zip from the above file names.

I'm trying as below, but not getting the correct value though:

echo "$fl_name" | sed 's#^[-[:alpha:]_[:digit:]]*##'

fl_name is the variable containing the file name.

Thanks a lot in advance!

like image 693
User123 Avatar asked Oct 26 '21 15:10

User123


People also ask

How do you name a release in Jira?

Navigate to your project. In the project menu, click on Releases. Select the Version name text box, enter a name, and click Add. Version names are typically numeric, for example, 1.0 or 2.1.

How do you inject bamboo variables?

The Inject Bamboo variables task allows you to read the values for variables from a file, and create those variables in your build plan. The file should use a 'key=value' format. Note that starting from Bamboo version 5.14, you must provide relative paths to the property file.

How do I get the values file for a specific release?

Using the helm get values command downloads the Values file for a specified release. Once you review the revisions, you may decide to start from scratch or rollback to a past revision.

How do I get values from helm release?

Get Helm Values. To get values from a Helm release, use: helm get values <release name>. For example: helm get values phoenix-chart. The output prints the user-supplied values for the current Helm release in YAML format: The user-supplied values are set when deploying a Helm chart. The set values override computed values.

How to get values of a helm release in JSON format?

For example, to get values of a helm release from the first revision in JSON format, use: A Helm release has Values stored with the initial release. As newer releases get deployed, the values of a Helm chart change. Using the helm get values command downloads the Values file for a specified release.

What is the output of the helm release template?

The output prints the computed values for the current Helm release in YAML format: When there are no user-supplied values, the computed values are pulled from the template to show a default value. Helm releases usually have multiple revisions.


Video Answer


6 Answers

You are matching too much with all the alpha, digit - and _ in the same character class.

You can match alpha and - and optionally _ and alphanumerics

sed -E 's#^[-[:alpha:]]+(_[[:alnum:]]*-)?##' file

Or you can shorten the first character class, and match a - at the end:

sed -E 's#^[-[:alnum:]_]*-##' file

Output of both examples

5.12.0.38-quality.zip
5.12.0.38-quality.zip
5.12.0.38-quality.zip
like image 140
The fourth bird Avatar answered Oct 21 '22 10:10

The fourth bird


With GNU grep you could try following code. Written and tested with shown samples.

grep -oP '(.*?-){2}\K.*'  Input_file

OR as an alternative use(with a non-capturing group solution, as per the fourth bird's nice suggestion):

grep -oP '(?:[^-]*-){2}\K.*' Input_file

Explanation: using GNU grep here. in grep program using -oP option which is for matching exact matched values and to enable PCRE flavor respectively in program. Then in main program, using regex (.*?-){2} means, using lazy match till - 2 times here(to get first 2 matches of - here) then using \K option which is to make sure that till now matched value is forgotten and only next mentioned regex matched value will be printed, which will print rest of the values here.

like image 39
RavinderSingh13 Avatar answered Oct 21 '22 12:10

RavinderSingh13


It is much easier to use cut here:

cut -d- -f3- file

5.12.0.38-quality.zip
5.12.0.38-quality.zip
5.12.0.38-quality.zip

If you want sed then use:

sed -E 's/^([^-]*-){2}//' file

5.12.0.38-quality.zip
5.12.0.38-quality.zip
5.12.0.38-quality.zip
like image 4
anubhava Avatar answered Oct 21 '22 11:10

anubhava


Assumptions:

  • all filenames contain 3 hyphens (-)
  • the desired result always consists of stripping off the 1st two hyphen-delimited strings
  • OP wants to perform this operation on a variable

We can eliminate the overhead of sub-process calls (eg, grep, cut and sed) by using parameter substitution:

$ f1_name='rzp-ASQ_TFC-5.12.0.38-quality.zip'

$ new_f1_name="${f1_name#*-}"                     # strip off first hyphen-delimited string
$ echo "${new_f1_name}"
ASQ_TFC-5.12.0.38-quality.zip

$ new_f1_name="${new_f1_name#*-}"                 # strip off next hyphen-delimited string
$ echo "${new_f1_name}"
5.12.0.38-quality.zip

On the other hand if OP is feeding a list of file names to a looping construct, and the original file names are not needed, it may be easier to perform a bulk operation on the list of file names before processing by the loop, eg:

while read -r new_f1_name
do
    ... process "${new_f1_name)"

done < <( command-that-generates-list-of-file-names | cut -d- -f3-)
like image 1
markp-fuso Avatar answered Oct 21 '22 10:10

markp-fuso


In plain bash:

echo "${fl_name#*-*-}"
like image 1
M. Nejat Aydin Avatar answered Oct 21 '22 10:10

M. Nejat Aydin


You can do a reverse of each line, and get the two last elements separated by "-" and then reverse again:

cat "$fl_name"| rev  | cut -f1,2 -d'-' | rev
like image 1
alift Avatar answered Oct 21 '22 10:10

alift