I have an agent version file that I need to parse to get version information about the application. The contents (example) of the version file is /opt/app_folder/agent_version.txtas follows:
Version: 10.2.4.110
Pkg name: XXXX-10.2.4-Agent-Linux-x86_64
Revision: 110
Patch version: 23
I need a conclusion as the 1st 3rd number of Versionand the number of Release version. For example, for example:
Current Version: 10.2.4.23
So, I used the following to achieve this in a shell using awk
FILE=/opt/app_folder/agent_version.txt
my_ver=`awk -F[:.] '/Version/ {gsub(" ",""); print $2"."$3"."$4}' ${FILE}`
OR
my_ver=`awk -F[-] '/Pkg/ {print $2}' ${FILE}`
my_patch=`awk -F[:.] '/version/ {gsub(" ",""); print $NF}' ${FILE}`
my_cur_ver="$my_ver.$my_patch"
echo $my_cur_ver
10.2.4.23
How to achieve this result in Python? Use regex or split or a combination of both?
I use Python 3.3onRHEL 6.2 x86_64
source
share