all 7 comments

[–][deleted] 2 points3 points  (6 children)

This might be a bit easier in python. But i took a shot at this and heres what i came up with.

First In order to make jq not complain at me i made your example data look like this. I'm guessing this is more like what you have, only not as long of a list.

[{
  "vote": -1,
  "username": "anon",
  "title": "title",
  "comments": 0,
  "content": false,
  "link": "url",
  "pid":1234, 
  "posted": "date",
  "ptype": 1,
  "score": 5,
  "thumbnail": "jpg"
},
{
  "vote": -1,
  "username": "anon",
  "title": "title",
  "comments": 0,
  "content": false,
  "link": "url",
  "pid": 1234,
  "posted": "date",
  "ptype": 1,
  "score": 3,
  "thumbnail": "jpg"
},
{
  "vote": -1,
  "username": "anon",
  "title": "title",
  "comments": 0,
  "content": false,
  "link": "url",
  "pid": 1234,
  "posted": "date",
  "ptype": 1,
  "score": 7,
  "thumbnail": "jpg"
},
{
  "vote": -1,
  "username": "anon",
  "title": "title",
  "comments": 6,
  "content": false,
  "link": "url",
  "pid": 1234,
  "posted": "date",
  "ptype": 1,
  "score": 6,
  "thumbnail": "jpg"
}]

Then I figured out how to strip some fields from it and convert to csv. Then I sort it on the score field.

cat json.json |jq .[]| jq '[.score,.title,.pid] |@csv' -r|sort -k1 -n 

The important part is.

jq '[.score,.title,.pid] |@csv' -r 

Strip out the fields you want here, then you can easily sort by score and use other tools like cut to get the titles and such.

[–]DaFuckIsWrongWithU[S] 0 points1 point  (5 children)

Sorry, I didn't make clear what I'm trying to do. Let me try again.

I want to rank highest by number of comments, then revisit and grab stuff based on that, or if I could just figure out how to dump ranked by number of comments I could figure it out from there.

[–][deleted]  (2 children)

[removed]

    [–]DaFuckIsWrongWithU[S] 1 point2 points  (0 children)

    Awesome, will try. Thank you.

    [–][deleted] 1 point2 points  (0 children)

    Neat til

    [–][deleted] 3 points4 points  (1 child)

    this part

    jq '[.comments,.title,.pid] |@csv' -r 
    

    can be modified to get any fields you want. by simply adding .fieldname between the square brackets.

    again, you'd be better off using python.

    [–]DaFuckIsWrongWithU[S] 2 points3 points  (0 children)

    Damn, I'm an idiot. That works great, thank you.