Skip to content

Instantly share code, notes, and snippets.

@PatrickCronin
Created July 7, 2020 19:36
Show Gist options
  • Save PatrickCronin/07dc0600f45721ec8352a898c8349326 to your computer and use it in GitHub Desktop.
Save PatrickCronin/07dc0600f45721ec8352a898c8349326 to your computer and use it in GitHub Desktop.
foreach inputs as $in (
{};
if has("postcode") and has("network") then null
else . as $x
| $in
| if length == 1 and .[0][-1] == "Record" then {}
elif length == 2 and .[0][-1] == "Network" then ($x + {network: .[-1]})
elif length == 2 and .[0][-2] == "postal" and .[0][-1] == "code" and .[-1] == "12061" then ($x + {postcode: .[-1]})
else $x
end
end;
select( has("postcode") and has("network") ) | .network
)
@PatrickCronin
Copy link
Author

Run as: mmdbinspect -db /usr/local/share/maxmind/GeoIP/GeoIP2-City.mmdb 0.0.0.0/0 | jq --stream -nr -f networks-for-postcode.jq.

Note that mmdbinspect is not fully capable of being used like this as it doesn't stream its output. Memory runs out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment