Skip to content

Instantly share code, notes, and snippets.

@porjo
Last active November 16, 2017 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save porjo/e26b9314f2d449a06c8e6100acaab972 to your computer and use it in GitHub Desktop.
Save porjo/e26b9314f2d449a06c8e6100acaab972 to your computer and use it in GitHub Desktop.
jq JSON utility - cheatsheet

Apache Logs

Output entries between 2 times, showing IP and query

$ cat access_log.json | \
  jq -r 'select (.time > "2017-10-21T02:00:00.000Z" and .time < "2017-10-22T02:00:00.000Z") | [.remote_addr,.query] | @csv'

Output entries where client IP matches prefix

$ cat access_log.json | \
  jq -r 'select ((.remote_addr | contains("1.2.3.")) and .time > "2017-11-16T03:00:00.000Z") | [.remote_addr,.host,.query] | @csv'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment