I would like to extract from a package name only the version of the package. Assuming I have a variable var that contains a package name (E.g.: var=nfs-utils-1.2.6-6.fc17.i686.rpm ). The string extracted would be 1.2.6-6. The method used to parse can be anything (regex, awk, cut).Edit:In the example above  I would actually like to extract 1.2.6
Extract only version portion of a package name with bash
bash;shell script;rpm;version
This is not very portable, but for this specific case, this grep works:echo $var | egrep -o '[0-9].*-[0-9]'1.2.6-6