Interview Prep/Shell Scripting/Scenarios: text processing and scheduling decisions

From JSON Lines application logs, count unique users per day.

IntermediateScenarioScenarios: text processing and scheduling decisions
Answer

Situation read → Extract (date, user) pairs, de-duplicate, count per date.

What I'd do →

jq -r 'select(.user_id != null) | "\(.ts[0:10]) \(.user_id)"' app-*.jsonl |
  sort -u | awk '{n[$1]++} END {for (d in n) print d, n[d]}' | sort
  1. .ts[0:10] slices the date from an ISO timestamp.
  2. sort -u removes duplicate (date, user) pairs; awk counts per day.
  3. For huge files, LC_ALL=C sort -u -S 1G --parallel=4.

Why → De-duplicating pairs before counting is the shell equivalent of COUNT(DISTINCT user_id) GROUP BY day.

Interview tip → Mention handling lines that are not JSON with jq -R 'fromjson? | ...'.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: text processing and scheduling decisions