Before this lesson, complete bash-pipelines, bash-loops-arrays.
This course runs GNU Bash with ordinary GNU text tools in a fresh Linux sandbox.
Small text tools work well when the input format and output contract are explicit. This lab uses a deliberately simple two-field format with no quoting or embedded commas. A real CSV document with quoted delimiters needs a CSV parser. State the supported grammar before choosing a field splitter; otherwise apparently convenient parsing can silently accept malformed records.
Apply the contract
Awk evaluates a program for each record and can keep an associative total per name. Validate both the field count and the grammar of each field before updating the total. NF == 2 rejects an extra comma rather than ignoring it. Addition assignment accumulates repeated names; ordinary assignment would retain only the last score. Zero is still a valid score and should create a report entry.
printf 'b,2\na,5\nb,3\n' | awk -F, '{sum[$1]+=$2} END {for (k in sum) printf "%s=%d\n",k,sum[k]}' | sortReason about the edge cases
Associative iteration order is not the report's requested order. Emit records and sort them under an explicit locale; the runner supplies LC_ALL=C so names are compared consistently. C-locale ordering is byte-oriented rather than a promise of natural-language collation. A final input record need not end with a newline, and empty input should produce no invented total. Build tests around repeated keys, zero values, malformed records and the final unterminated record. Keep intermediate data in the pipeline when possible instead of constructing command text or evaluating a generated shell program.
Practice
Read simple comma-delimited records NAME,SCORE from stdin. Valid names match [A-Za-z_][A-Za-z0-9_]* and scores contain only decimal digits. Skip malformed records, including extra fields. Scores and totals fit within one million. Sum scores per name and output NAME=TOTAL in C-locale name order. Empty input produces no output. This format has no quoted CSV fields.
Run sample starts again from the first public fixture and grants no mastery evidence. Submit checks all fixtures, including edge cases. Read the specification before editing; the bug and fill phases share the build’s contract. Flashcards reinforce recall on a separate schedule.