Bash sort and uniq
Count repeated labels after making equal records adjacent.
How it works
sort orders records according to its comparison and locale settings. uniq combines adjacent equal lines, so it does not count repetitions scattered throughout an unsorted stream. Numeric ordering requires an explicit numeric comparison when values are numbers rather than text. A stable locale helps make examples reproducible, but domain-specific collation may need a different choice.
Run the code
Reviewed with Git for Windows Bash 5.2.37. Open Git Bash, save the download with LF line endings in a separate learning folder, check it with bash -n lesson-name.sh, then run bash lesson-name.sh using the actual filename. Bash 4 or newer is required for the full course. Linux-only notes identify unavailable tools or POSIX behaviour. There is no Bash browser runner; Apache and MySQL are not required.
This complete example was executed in the stated local review environment.
Example
#!/usr/bin/env bash
set -u
set -o pipefail
export LC_ALL=C
printf "north\nsouth\nnorth\n" | sort | uniq -c | awk '{ printf "%s=%d\n", $2, $1 }'
Expected result
north=2 south=1
Sorting makes the north labels adjacent before uniq counts them. The final awk formats the result without depending on the padding used by uniq. These labels contain no whitespace, matching the fixture contract. For arbitrary records, preserve their true delimiter and do not assume a whitespace split is safe.
Primary technical reference: Bash documentation.