Parse version number

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

I'm writing an RPM build script and I need to parse out some information from a build number. The idea is every time a build is made the last place of the version is incremented by one automatically (This is done by a preset script in our build system).

The format that it requires is so: 1.0.0.[color:red]0[/color]. Where the last digit in red is auto incremented. For the RPM build I need to use that last digit as a release number and the previous 3 as the version.

Example: 1.2.0.24 would turn into my_program-1.2.0-24.noarch.rpm.

I've tried my hand at grep and sed to try and extract each piece of the version but with no luck.

Right now Im using this to pull the entire number
Code: [ Select ]
cat $SRC_DIR/Makefile.inc | grep RELEASE_VERSION | sed 's/[^0-9\.]//g'


Where the file format of Makefile.inc is as follows:
Code: [ Select ]
RELEASE_PRODUCT="Product Name"
RELEASE_VERSION="1.2.0.24"
  1. RELEASE_PRODUCT="Product Name"
  2. RELEASE_VERSION="1.2.0.24"
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

After quite a bit of digging I found something that works. Probably not the best way to do it but it works for me.

Code: [ Select ]
export VERSION=`cat $SRC_DIR/Makefile.inc | grep RELEASE_VERSION | sed 's/[^0-9\.]//g' | cut -d . -f 1-3 | sed s/" "//g`
export RELEASE=`cat $SRC_DIR/Makefile.inc | grep RELEASE_VERSION | sed 's/[^0-9\.]//g' | cut -d . -f 4 | sed s/" "//g`
  1. export VERSION=`cat $SRC_DIR/Makefile.inc | grep RELEASE_VERSION | sed 's/[^0-9\.]//g' | cut -d . -f 1-3 | sed s/" "//g`
  2. export RELEASE=`cat $SRC_DIR/Makefile.inc | grep RELEASE_VERSION | sed 's/[^0-9\.]//g' | cut -d . -f 4 | sed s/" "//g`

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 69 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.