Reputation: 578
So, I have a JSON array:
[ "3.22-SNAPSHOT_293022", "3.22-SNAPSHOT_296087",
"3.22-SNAPSHOT_latest", "3.22.1_293094", "3.22.1_296087",
"3.22.1_latest",, "3.23-SNAPSHOT_308024", "3.23-SNAPSHOT_308310", "3.23-SNAPSHOT_latest", "3.23.1_307802", "3.23.1_308022",
"3.23.1_latest", "4.0-SNAPSHOT_307842", "4.0-SNAPSHOT_307938",
"4.0-SNAPSHOT_308031", "4.0-SNAPSHOT_308193",
"4.0-SNAPSHOT_308308", "4.0-SNAPSHOT_308310", "latest" ]
First number indicates the version no. 2nd number indicates sub version number. I want to de-delect the items such that, a. 2 highest version numbers (which is not a snapshot) have 2 sub version left b. 2 highest version numbers (snapshot) have 2 sub version left c. rest versions have 1 subversion left.
Other entries can be deleted. Any point for the ways to do it would be great..
Upvotes: 0
Views: 42
Reputation: 6079
Ways to do it:
-V
(--version-sort
) option of sort(1) and the jq utility to deal with JSON.I would opt for the latter... I'll leave the fun up to you until you request help with some code that you've tried.
Upvotes: 1