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!
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.
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.
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.
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.
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.
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.
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
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.
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
Assumptions:
-
)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-)
In plain bash:
echo "${fl_name#*-*-}"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With