Sort Lines
Sort lines alphabetically, numerically, ascending or descending. Options for case sensitivity and blank line removal.
What is Sort Lines?
A line sorter arranges lines of text in alphabetical, reverse alphabetical, numerical, or custom order. It handles common sorting needs that are cumbersome in text editors — sorting imports in code files, organizing lists, alphabetizing names, ordering data by numeric value, and removing duplicates while sorting. It supports case-sensitive and case-insensitive sorting, natural number ordering (so 'item2' comes before 'item10'), and reverse sort.
How It Works
The tool splits your input text on newline characters into individual lines, then applies the selected sorting algorithm. Alphabetical sort uses locale-aware string comparison for correct ordering of accented and international characters. Natural sort treats embedded numbers as numeric values rather than character sequences. Numeric sort extracts the first number from each line and sorts by that value. You can optionally remove duplicates, trim whitespace, and remove empty lines during the sort operation.
Common Use Cases
- •Alphabetizing import statements in JavaScript, Python, or Java source files
- •Sorting name lists, glossary terms, or index entries for publications
- •Ordering CSV data by a column value when you can't open it in a spreadsheet
- •Sorting server log entries, error messages, or event lists by timestamp
- •Organizing configuration file entries (environment variables, settings) alphabetically
- •Cleaning up and ordering TODO lists, bookmarks, or link collections
Frequently Asked Questions
Can I sort numbers correctly?▼
Yes, enable 'Numeric sort' to sort by numerical value instead of alphabetically.
Why did my numbers sort as 1, 10, 2, 20, 3?▼
That is alphabetical sorting, which compares character by character, so "10" comes before "2" because "1" is less than "2". Switch to numeric sorting to get 1, 2, 3, 10, 20. This is the single most common surprise when sorting lists of numbers.
How does case-sensitive sorting differ from case-insensitive?▼
Case-sensitive sorting uses character codes, so every uppercase letter sorts before every lowercase one — "Zebra" lands before "apple". Case-insensitive sorting compares letters as though they were all one case, giving the alphabetical order most people expect: apple, Banana, Zebra.
Can I sort by line length instead of alphabetically?▼
Yes. Sorting by length is handy for spotting outliers — the longest lines in a log file are often the ones with stack traces, and the shortest lines in a keyword list are usually the broadest head terms.
Does sorting remove duplicate lines?▼
Not by default; duplicates end up next to each other but are all kept. Enable the deduplicate option, or run the Remove Duplicate Lines tool afterwards, if you want a unique list.
How are blank lines and leading whitespace treated?▼
A space sorts before any letter or digit, so indented lines drift to the top and can look misplaced. Trim whitespace before sorting if your lines are indented. Blank lines are collected together, normally at the start of an ascending sort.
Is there a limit on how many lines I can sort?▼
There is no fixed cap. Sorting happens in your browser, so the practical limit is your device's memory. Lists in the tens of thousands of lines sort essentially instantly on a modern machine.
Further Reading
Related Tools
More from Text Tools:
Remove Duplicate Lines
Remove duplicate lines from text instantly. Keep unique lines with case-sensitive or case-insensitive matching. Free online tool.
Add Line Numbers
Add line numbers to text. Customize start number, separator, and zero-padding. Free online line numbering tool.
Reverse Text
Reverse text by characters, words, or lines. Create mirror text, flip word order, or reverse line order instantly.