I've a agent version file that I need to parse to get the application version details.
The (example) contents of version file /opt/app_folder/agent_version.txt
is as below:
Version: 10.2.4.110
Pkg name: XXXX-10.2.4-Agent-Linux-x86_64
Revision: 110
Patch version: 23
I need the output as 1st 3 numbers from Version
and the number from Release version
.
For e.g.:
Current Version: 10.2.4.23
So, I've used the below to achieve this in 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 do I achieve this result in Python? Use regex or split or a combination of both?
I'm using Python 3.3
on RHEL 6.2 x86_64