Interview Prep/Real-World Interview/awk, sed, grep and jq one-liners

Sum the response sizes (field 10) in an Nginx access log and print the total in MB.

BeginnerHands-onawk, sed, grep and jq one-liners
Answer
awk '$10 ~ /^[0-9]+$/ {s += $10} END {printf "%.2f MB\n", s/1024/1024}' access.log

Key trick → The regex guard skips - values (no body), which would otherwise be counted as 0 silently or break other tools.

All Real-World Interview questions Roadmap: Interview readiness

More on awk, sed, grep and jq one-liners