Results 1 to 2 of 2
Hi,
I have the following requirement.
There will be following text/line in a file (eg: search-build.txt)
PRODUCT_VERSION="V:01.002.007.Build1234"
I need to update the incremental build number (eg here 007) every time ...
- 12-01-2011 #1
Bash shell script: Str(007) to int(7),increment it(8) & convert back t
Hi,
I have the following requirement.
There will be following text/line in a file (eg: search-build.txt)
PRODUCT_VERSION="V:01.002.007.Build1234"
I need to update the incremental build number (eg here 007) every time I give a build through script. I am able to search the string and get the item.
Outputrexpression_sed='PRODUCT_VERSION=\"V:\([0-9]*\).\([0-9]*\).\([0-9]*\).Build\([0-9]*\)\"'
var2=`grep -sn $rexpression_sed search-build.txt | sed -e 's/'$rexpression_sed'/\1\t\2\t\3\t\4/g'| cut -f 3`
echo $var2
007
How to convert this to integer (7), add 1 to it (
and again get back in the same form (00
in the easiest way? I will be using sed -i on the file, with this new string that can be used with RE for replacing that part!
Or
Is there any better method than above.
Thanks for any help.
- 12-01-2011 #2
Re: Bash shell script: Str(007) to int(7),increment it( & convert back to string(00
thanks solved
newval=0
filename=search-build.txt
rexpression_sed='PRODUCT_VERSION=\"V:\([0-9]*\).\([0-9]*\).\([0-9]*\).Build\([0-9]*\)\"'
incrementnum=`grep -sn $rexpression_sed $filename | sed -e 's/'$rexpression_sed'/\1\t\2\t\3\t\4/g'| cut -f 3`
echo "Current Incremental number is: " $incrementnum
if [ $incrementnum ]
then
calcval=$(expr $incrementnum + 1)
#echo $calcval
if [ $calcval -le 9 ];
then
newval="00$calcval"
elif [ $calcval -le 99 ];
then
newval="0$calcval"
else
newval="$calcval"
fi
echo "New Incremental number is: " $newval
rexpression_rep_final='PRODUCT_VERSION="V:\1.\2.'$ newval'.Build\4"'
#replace with new number
sed -i 's/'$rexpression_sed'/'$rexpression_rep_final'/' $filename
fi


Reply With Quote