DisplayName
DisplayName

Reputation: 649

Produce output for values greater than n and ignore the rest in JQ

I am trying to display only lines with second value greater than 1000. The original JQ program I am using to display everything is:

jq -r '.[] | [.name, .size] | join(",")' file.json

This gives me:

name1,1024
name2,300
name3,512

If I select values only greater than 1000:

jq -r '.[] | [.name, .size | select(. > 1000)] | join(",")' file.json

then I am getting:

name1,1024
name2
name3

How can I discard lines with size less than 1000?

Upvotes: 6

Views: 4434

Answers (1)

oguz ismail
oguz ismail

Reputation: 50775

Select objects, not fields.

.[] | select(.size > 1000) | [.name, .size] | join(",")

Online demo

Upvotes: 10

Related Questions