Email addresses are a classic trap for deduplication: the domain part is case-insensitive by spec, but the local part before the @ technically isn't — User@example.com and user@example.com could in principle be two different mailboxes, even though almost every real-world mail provider treats them as the same one in practice.
Alphabetical sorting vs numeric sorting
Alphabetical (lexicographic) sorting compares strings character by character as text. Because of this, the string "10" ends up before "9", since the character "1" is lexicographically smaller than "9" — sorting doesn't "understand" that these are numbers. Numeric sorting, by contrast, parses strings as numbers before comparing, giving the expected order 9, 10, 11.
Case sensitivity in sorting
In most systems, uppercase letters lexicographically precede lowercase ones (due to character encoding), so "Zebra" might end up before "apple" under case-sensitive sorting. Case-insensitive sorting first normalizes strings to the same case for comparison, while keeping the original casing in the output.
What counts as a duplicate isn't always obvious
Deduplication compares lines character by character, not by meaning. The email address case is a good example of a broader issue: two strings can be "the same" by every practical convention while still differing at the byte level, so whether they collapse to one line depends entirely on which normalization rule — if any — gets applied before comparing.
Why you need this
- Removing repeated entries from a list of email addresses or URLs before an import.
- Sorting a list of versions or IDs numerically instead of as text.
- Quickly comparing two datasets by bringing both lists to the same sorted form.
Natural sort
Natural sort is a compromise between alphabetical and numeric sorting: it recognizes digit runs within a string as numbers while comparing the rest of the characters as text. That's why file2.txt ends up before file10.txt, even though formally these are strings rather than standalone numbers — useful for filenames or versions with a text prefix.