Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

bash get first element before the first integer of a variable

I want to get the first element before the first integer of a variable,
For example, I have this variable:

FILE=normalize-component-0.0.3-SNAPSHOT-jar-with-dependencies-package-58.jar

And I want to get the application name which is the name "normalize-component" in that case that always comes before an integer.

Take in mind that the application name can always change but the structure will always be:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{application_name}-{digit}-{*}-jar-with-dependencies-package-{digit}.jar

desired output:

APP_NAME=normalize-component

>Solution :

Use parameter expansion in bash:

$ FILE="normalize-component-0.0.3-SNAPSHOT-jar-with-dependencies-package-58.jar"

$ echo "${FILE%%-[[:digit:]]*}"
normalize-component
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading