Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 5
    The jq solution is worthy of a special mention, since it's succinct, and re-purposes the tool in a non-obvious way. Commented May 10, 2017 at 11:31
  • 3
    beautiful! wish i could give +2 Commented Jul 19, 2017 at 21:16
  • 1
    Extended a little: jq -s '{ min:min, max:max, sum:add, count:length, avg: (add/length), median: (sort | .[ length/2 ]) }' shows the output as an object with labels, pretty printed with colors! Commented Sep 24, 2020 at 20:14
  • 1
    @Grynn That's not right for median. For an odd list echo '[1,2,3]' | jq 'sort | .[length/2]' your code gives the answer 'null', and for an even list echo '[1,2,3,4]' | jq 'sort | .[length/2]' your code picks the third element '3' but it should give the answer 2.5, the mean of the middle two elements. Commented Nov 12, 2020 at 18:14
  • @LucianWischik - Good point! Probably better to fix this is a public gist, rather than comment stream ... but jq 'sort | .[(length/2) | floor] would work for odd length lists? Cannot think of a very compact way to handle even lists Commented Nov 14, 2020 at 13:46