Sort Lines Alphabetically
Sort lines ascending or descending with natural-number ordering and dedupe.
Written by Anil Gautam · Updated
How are numbers inside lines compared?
Natural order, which is on by default, compares each run of digits as a whole number. Chapter 10, Chapter 2, chapter 1 and Chapter 2 sort to chapter 1, Chapter 2, Chapter 2, Chapter 10. With natural order off, comparison goes character by character, so Chapter 10 lands before Chapter 2 because the character 1 comes before 2.
A decimal point is read as a separator between two numbers. That suits version numbers, where 1.2, 1.5, 1.9 and 1.10 come out in release order, but decimal values go wrong: 0.5, 0.25 and 0.125 sort in that order, which is the reverse of their size. Minus signs are compared as punctuation, so -5 lands before -10. Sort numeric columns like these in a spreadsheet.
How do the case, duplicate and trim options interact?
With Case-sensitive off, Apple and apple count as equal and keep their input order. Accents are ignored in both modes, so résumé and resume also tie. Case-sensitive on keeps alphabetical order and uses case only to separate otherwise identical words, lowercase first with English settings: banana, Apple, apple and Cherry become apple, Apple, banana, Cherry. Descending order is the ascending result reversed, so tied lines swap places too.
Remove duplicates matches lines exactly whatever the case setting, so Apple, apple and APPLE all survive. It runs after trimming, so with Trim whitespace on, a line with a trailing space counts as a copy of the same line without one. Blank lines are kept and sort to the top, or to the bottom in descending order, and Remove duplicates cuts them to one.
The numbers beside the two box labels count lines in and out. With Remove duplicates on, the gap between them is the number of repeats removed, so the chapter list above goes from 4 lines to 3. A line that starts with a space sorts ahead of every line that starts with a letter once Trim whitespace is off.
Which list tool fits your task?
This tool always reorders the list. Remove Duplicate Lines drops repeats and keeps the first copy of each line in its original position. Duplicate Item Counter shows how many times each value occurs and can count Apple and apple together. Compare Lists finds what one list has and another lacks.
Sorting runs in your browser and follows its language settings, so a Swedish-language browser puts å after z, where an English one files it with a.