4 ms·
You may be interested in jq: > jq is like sed for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that
by throw0101a 6y ago
You may be interested in jq:
> jq is like sed for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text.
* https://stedolan.github.io/jq/ https://stedolan.github.io/jq/
- npteljes 6y agoI love jq. The simple usecase of piping a json to "jq .", having it pretty-printed is awesome in itself.
- geek_at 6y agoalso someone tell them about curl
- throw0101a 6y agoI default to wget because as a sysadmin I usually want to download a file, and that is the default behaviour. Perhaps devs default to curl because they want to pipe things.
- tempest_ 6y agoWith jq and curl curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq '.prefixes | .[].ip_prefix | .[-3:]' | sort | uniq -c
- xorcist 6y ago".a | .b" is just ".a.b" in jq. Netmasks might not always be three characters. Perhaps something like this: curl -sf https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[].ip_prefix' | grep -o '/.*' | sort | uniq -c If you really wanted to, you could even do the splitting and counting in jq: curl -sf https://ip-ranges.amazonaws.com/ip-ranges.json | jq 'reduce (.prefixes[].ip_prefix | split("/")[1]) as $mask ({}; .[$mask] += 1)' It's a super handy tool with a real language in there!
- samoa42 6y agohow does jq solve the problem more elegant/shorter/readable/portable?