I use sed in CentOs to extract version number and it's work fine:
echo "var/opt/test/war/test-webapp-4.1.56.war" | sed -nre 's/^[^0-9]*(([0-9]+\.)*[0-9]+).*/\1/p'
But my problem is that i am not able to extract when the version is shown like this:
var/opt/test/war/test-webapp-4.1.56-RC1.war
I want to extract the 4.1.56-RC1 if it is present.
Any ideas ?
EDIT 2
Ok to be clear take this example, with a path:
Sometimes the path contains only a serial number like this var/opt/test/war/test-webapp-4.1.56.war and sometimes it contains a series of numbers and letters like this "var/opt/test/war/test-webapp-4.1.56-RC1.war
The need is to recover either 4.1.56 or 4.1.56-RC1 depending on the version present in the path. With sed or grep, no preference.
This seems to work but the .war is shown at the end:
echo "var/opt/test/war/test-webapp-4.1.56.war" | egrep -o '[0-9]\S*'
echo "version ..." | awk '{print $2}'?because maybe the extract is make from a path like this: /var/opt/test/war/test-webapp-4.1.56-RC1.war- so what if it was? Don't answer that in a comment but instead edit your question to show examples of all possible version info formats that you want to be able to handle along with the expected output for each.