Interview Prep/Shell Scripting/find, xargs, jq and yq

What does `jq -s`, `jq -n` and `jq -c` do?

IntermediateConceptfind, xargs, jq and yq
Answer
  • -s (slurp): read all input values into one array, e.g. combine many JSON lines.
  • -n (null input): do not read input; build JSON from --arg values.
  • -c (compact): one line per output value, ideal for JSON Lines logs.
cat events/*.json | jq -s 'map(select(.level == "error")) | length'
jq -n --arg host "$(hostname)" --argjson pct 93 '{host: $host, disk_pct: $pct}'
jq -c '.items[]' pods.json | while IFS= read -r pod; do jq -r .metadata.name <<<"$pod"; done
All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on find, xargs, jq and yq