Skip to content

Instantly share code, notes, and snippets.

@sepastian
Created September 17, 2024 06:30
Show Gist options
  • Save sepastian/eaa2a6c668330214e1bb1240fe65b932 to your computer and use it in GitHub Desktop.
Save sepastian/eaa2a6c668330214e1bb1240fe65b932 to your computer and use it in GitHub Desktop.
jq: select objects missing a specific attribute
#!/bin/bash
set -euo pipefail
# Select all objects which do not contain an attribute named 'message'.
#
# Background: a log file contains messages from an application and
# numerous messages from Mongo db; the messages from Mongo contain
# an attribute called 'message', the application logs contain 'msg'
# instead. Filter the application logs only by selecting all objects
# which do not contain the 'message' attribute.
jq 'select(.message|not)' logs.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment