How do you read structured log lines (JSON Lines) and filter by fields?
IntermediateConceptfind, xargs, jq and yq
Answer
# errors from the payments service in the last file, with timestamp and message
jq -r 'select(.level == "error" and .service == "payments") | "\(.ts) \(.msg)"' app.jsonl
# tolerate non-JSON lines mixed in
jq -R -r 'fromjson? | select(.status >= 500) | .path' app.log | sort | uniq -c | sort -rn
-R reads raw lines, fromjson? parses each and silently skips lines that are not valid JSON.
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