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--argvalues.-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
More on find, xargs, jq and yq
What are the most useful `find` predicates for operations work?BeginnerWhat is the difference between `-exec cmd {} \;`, `-exec cmd {} +` and `-delete`?IntermediateHow does `find` evaluate `-o` (OR) and why do you need parentheses?AdvancedWhat does `xargs` do, and which flags matter?IntermediateWhy is `find | xargs rm` dangerous and what is the safe form?IntermediateWhat is `jq` and what are the filters you use every day?Beginner