LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Parse RPM version string in Bash (https://www.linuxquestions.org/questions/linux-newbie-8/parse-rpm-version-string-in-bash-295973/)

jimwelc 02-28-2005 03:48 PM

Parse RPM version string in Bash
 
Hello,

I am very new to bash scripting and I am trying to break down a rpm version string into four separate strings.

Basically I have a Version string I retrieve from a file( for example sake lets say it is "1.0.1-05" and I would like to break it down and store it into four separte strings/or numbers. I think I might be able to use the awk/sed command to do this but I can not figure out the usage.

VER_STR="1.0.1-05"

#Perform sed awk to Parse out
#version values as followes
# VER_MAJOR="1"
# VER_MINOR="0"
# VER_BUILD="1"
# VER_REL="05"



Any suggestions or help will be greatly appreciate.


Best Regards,
-Jim

btmiller 02-28-2005 05:22 PM

This is harder than in initially appears (I know, I've tried it) because there is not standard way of doing version numbers. You might want to tackle this with Perl and handle a few common cases (you can to it with sed or awk, but when things get this heavy I tend to go for Perl). You'd want to use the split routine to split the string into its component parts. Maybe ifyou google you'll find a pre-rolled solution...


All times are GMT -5. The time now is 06:14 AM.