Pick up the latest releases from each major node version with jq Pick up the latest releases from each major node version with jq json json

Pick up the latest releases from each major node version with jq


You could pipe to this awk command:

awk -F. '!major[$1]++'

It uses the period as the field separator and prints every line of which it has never seen the first field, which is the major version.

In case the input is not sorted and you have GNU sort, you can use its version sort:

sort -rV | awk -F. '!major[$1]++'

where -V is for "version sort" and -r is for "reverse".


If you pipe the output of curl into jq -r with the following filter, you should get the major versions, irrespective of how the version numbers are ordered in the curl results:

map(.name)| map(split(".") | map(tonumber? // .) )| group_by(.[0])| map(sort)| map( .[-1] | map(tostring) | join("."))| .[]

Variation

If you want the output sorted as well, simply remove the "v" beforehand, and then tack it on afterwards. In the interests of generality, let's define a function which will output the most recent release tag for each major release:

# Input: an array of "x.y.z..." strings, # some or all components of which may be integers# Output: a stream of the latest "major" releasesdef majors:  map( split(".") | map(tonumber? // .))  | group_by(.[0])  | map(sort[-1])[]  | map(tostring)  | join(".") ;map( .name[1:] ) | "v" + majors

Typescript

$ jq -rf major-version.jq input.jsonv8.11.2v9.11.1v10.1.0