I'm trying to write a shell script to increment a build number of a version stored in a JSON file.
{
/**
* The application's namespace.
*/
"name": "AppName",
/**
* The version of the application.
*/
"version": "1.0.0.23",
/**
* More comments.....
*/
....
}
I've already tested a simple way to increment the number if the variable was already in the file:
version='1.0.0.23'
a=( ${version//./ } ) # replace points, split into array
((a[3]++)) # increment revision (or other part)
version="${a[0]}.${a[1]}.${a[2]}.${a[3]}" # compose new version
echo $version # outputs: 1.0.0.24
I've looked at jq and jshon but neither will parse the JSON file because it contains comments (the app.json file is generated automatically by Sencha Cmd)
How can I read the version property using something like awk / sed and update it? Would jsawk be better?
Update
I've managed to extract the version number using this:
version=$( sed -n 's/.*"version": "\(.*\)",/\1/p' app2.json )
so now I can read the version and increment it. Just need to write it back now.