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

A vendor needs application logs, but they contain emails and card numbers. Mask them first.

IntermediateScenarioScenarios: text processing and scheduling decisions
Answer

Situation read → Redact with regexes, verify nothing remains, and share only what is needed.

What I'd do →

sed -E \
  -e 's/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/<email>/g' \
  -e 's/\b[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{1,4}\b/<card>/g' \
  -e 's/(Authorization: Bearer )[A-Za-z0-9._-]+/\1<token>/g' \
  app.log > app.redacted.log
grep -cE '[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}' app.redacted.log   # expect 0
  1. Verify with a second pass that searches for the patterns again.
  2. Reduce scope first (time window, relevant request IDs) so less data leaves.

Why → Logs are a frequent source of PII and secrets leaks; regex redaction plus verification is the minimum.

Interview tip → Mention fixing the root cause: applications should not log card numbers at all (PCI DSS).

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: text processing and scheduling decisions