Reputation: 63
I have a bundle version set in a file, like this:
"dist/app-build-v1.08": {
How can I sed the version number and swap it out with an incremented number?
First I'm attempting to grab the line itself, which is the third line in my bundle file.
BUILD=$(sed '3q;d' ./build/bundles.js)
Which does indeed grab the line. I found this snippet here on stack overflow:
's/[^0-9.]*\([0-9.]*\).*/\1/'
Which i'd like to use on $BUILD, but it doesn't work. The expected output for me would be
$NUM = "1.08"
Then I'd like increment it to 1.09, rebuild the string and used sed -i
to replace it.
Upvotes: 6
Views: 4259
Reputation: 14979
Another way :
sed -r '3s/.*build-v([0-9]+(\.[0-9]+)?).*/\1+0.01/' | bc -q
Example:
$ echo '"dist/app-build-v1.08": {' | sed -r 's/.*build-v([0-9]+(\.[0-9]+)?).*/\1+0.01/' | bc -q
1.09
Upvotes: 1
Reputation: 195269
It seems that the interesting line is always line 3. Then you can use this awk one-liner:
awk 'NR==3{gsub(/[^.0-9]+/,"");$0+=0.01;print}' file.js
0.01
to it. x.xx
. If it is not in this case, it is also possible to calculate the increment dynamically. like 0.01 or 0.00001
But extra implementation is required.1.09
Upvotes: 1