Sort Lines
Text ToolsSort text lines alphabetically, numerically, by length, randomly, or in reverse, with options for case sensitivity and duplicate removal.. Free, private — all processing in your browser.
The Sort Lines tool arranges text lines in alphabetical order (A to Z or Z to A), numerical order, by line length, in random (shuffled) order, or reversed — whatever arrangement you need. It sounds simple until you realize how often the task arises: a long list of email addresses needs alphabetizing before deduplication, URLs from a scrape need sorting for batch processing, imported data needs canonicalizing before comparison, a code file has scrambled import statements that should be tidied, a mixed list of numeric IDs and text needs natural sorting that handles embedded numbers correctly.
This tool handles every common sorting need in one interface. Paste lines, pick a sort mode, copy the result. Case-sensitive and case-insensitive modes available. Natural sort order handles embedded numbers (so file2 sorts before file10, not after, matching the Windows and macOS file browser convention). Locale-aware sorting uses the correct alphabetization for accented characters (German ß, Spanish ñ, French é). Duplicate removal and trimming of leading/trailing whitespace are optional post-processing steps. Works with lists of any size — thousands of lines process in milliseconds entirely in your browser.
Sort Lines — key features
Six sort modes
Alphabetical, reverse alphabetical, numeric, natural sort, by length, and random shuffle — covers every common sorting need.
Case sensitivity toggle
Switch between case-sensitive (A before a) and case-insensitive (A equivalent to a) ordering.
Natural sort
Sorts embedded numbers correctly so item-2 comes before item-10, matching file-browser ordering.
Locale-aware
Uses Intl.Collator with selectable locale for correct alphabetization of accented and non-Latin characters.
Remove duplicates
Optional deduplication removes consecutive equal lines after sorting — useful for cleaning imported lists.
Trim and blank line handling
Options to trim whitespace from each line and to keep or remove blank lines before sorting.
Preserves content safely
All sorting runs in your browser — email lists, URL logs, and other sensitive data never leave your machine.
Reverse order
One-click reversal produces Z-to-A or decreasing numeric order from any sorted result.
How to use the Sort Lines
- 1
Paste your lines
Drop the text into the input field — any number of lines, up to hundreds of thousands.
- 2
Choose a sort mode
Pick alphabetical, numeric, natural sort, by length, or random from the mode selector.
- 3
Set case sensitivity
Toggle case sensitive or insensitive depending on whether Aa should be treated as equivalent.
- 4
Optional — remove duplicates
Enable dedup to strip adjacent equal lines after sorting. Great for cleaning imported lists.
- 5
Copy the result
One-click copy sends the sorted lines to your clipboard, ready for paste into code, a spreadsheet, or email.
Common use cases for the Sort Lines
Data cleaning
- →Email list preparation: Sort and dedupe an email list before loading into a mailing platform to spot duplicates and verify alphabetical coverage.
- →URL list organization: Sort scraped URLs alphabetically before batch processing to ensure consistent ordering across runs.
- →CSV row ordering: Sort rows of a CSV by a specific column by extracting that column, sorting, and reassembling.
Development
- →Import statement tidying: Sort a code file’s import statements alphabetically for consistent style and easier code review.
- →Configuration file ordering: Put environment variables, dependency lists, or configuration keys in alphabetical order for readability.
- →Log line organization: Sort log entries by timestamp or message content when investigating incidents.
Writing and content
- →Glossary and index creation: Alphabetize terms for a glossary or index by pasting into the sorter.
- →Citation ordering: Sort citations alphabetically by author for a reference list in reports or academic writing.
- →Team roster: Alphabetize a team member list by name for a directory or organizational chart.
Sort Lines — examples
Basic alphabetical
Sorting a short list of names.
Charlie Alice Bob
Alice Bob Charlie
Natural sort
Embedded numbers handled correctly.
file10 file2 file1
file1 file2 file10 (lexicographic would give file1, file10, file2)
Numeric sort
Pure numbers sorted by value.
100 9 42 300
9 42 100 300
Sort with dedup
Duplicate entries removed after sort.
banana apple apple cherry
apple banana cherry
Random shuffle
Reorder lines randomly for unbiased processing.
task-A task-B task-C task-D
task-C task-A task-D task-B (example — result varies)
Technical details
Sorting text lines looks trivial — JavaScript has a built-in sort method — but the default behavior has enough pitfalls that a purpose-built tool is often worth the extra friction.
Default lexicographic sort compares character code points. This puts uppercase letters before lowercase (B before a) and digits before all letters (1 before A), which rarely matches human expectations. Case-insensitive sort uses .toLowerCase() on both sides of the comparison, giving the A-Z order most people want.
Locale-aware sorting uses Intl.Collator to produce correct ordering for the target language. In Swedish, å sorts after z; in German, ä sorts near a (standard) or near ae (DIN 5007); in Spanish, ñ sorts after n. The browser provides these via Collator — this tool exposes locale choice so you get the correct alphabetization for your content.
Natural sort (sometimes called version sort or human sort) treats embedded numeric substrings as numbers for comparison. So item-2, item-10, item-100 sort in that order, not item-10, item-100, item-2 (which is what lexicographic sort produces because 1 < 2 at the character level). Natural sort matters for file listings, version numbers, and any list where numbers appear within strings.
Numeric sort treats each line as a number and sorts by numeric value. Useful for lists of pure numbers, phone numbers (though leading-zero preservation matters there), or IDs. Lines that are not numeric go to the end by convention or trigger an error.
Sort by length is straightforward (sort by line.length), used for visual arrangement of text or finding the longest/shortest entries quickly.
Random sort uses the Fisher-Yates shuffle algorithm for uniform distribution. Standard JavaScript sort with Math.random() in the compare function does not produce a uniform shuffle — a known gotcha. The tool uses Fisher-Yates internally.
Removing duplicates after sorting uses a simple adjacent-comparison pass since equal items are adjacent after sort. Without sort first, you can use a Set to deduplicate in any order but lose the original sequence.
For very long lists (hundreds of thousands of lines), the browser handles them in-memory with minor delay. Lines over one million can cause memory pressure — split into chunks if you hit problems.
Common problems and solutions
⚠Default sort ignores case
Some tools put uppercase before lowercase (B before a). Ensure case-insensitive sort is selected for human-readable alphabetical order.
⚠Natural sort needed for numbered lists
item-1, item-2, item-10 sort as item-1, item-10, item-2 with default lexicographic sort. Use natural sort mode when lines have embedded numbers.
⚠Locale matters for accented characters
In French, é should sort near e. In Swedish, å sorts after z. Pick the correct locale for your content or the alphabetical order will look wrong.
⚠Leading whitespace affects sort
Lines starting with a space sort before other lines in lexicographic order. Enable the trim option if leading whitespace is accidental.
⚠Empty lines affect sort
Blank lines sort to the top in lexicographic order because empty strings come first. Remove blanks before sorting or enable the "skip blank lines" option.
⚠Duplicate removal only works adjacent
Simple deduplication relies on duplicates being adjacent (true after sort, not otherwise). If you dedup without sorting, use a Set-based approach that handles non-adjacent duplicates but may reorder lines.
⚠Shuffle not uniformly random
Using Math.random() in a sort compare function produces biased shuffles. The tool uses Fisher-Yates internally for true uniform shuffling.
Sort Lines — comparisons and alternatives
Compared to the Unix sort command, this tool is accessible without a terminal and handles edge cases (natural sort, locale awareness) via a simple UI. The CLI wins for scripting and very large files; this tool wins for interactive one-off tasks.
Compared to spreadsheet sort (Excel, Google Sheets), this tool is faster for simple line sorting — no need to open a spreadsheet, set up columns, or save. For multi-column sort or table-like data, a spreadsheet is the better choice.
Compared to text editor sort plugins (VS Code, Sublime), this tool gives the same result without requiring the plugin to be installed. Editor plugins are convenient when you are already editing; this tool is convenient when you are not.
Frequently asked questions about the Sort Lines
▶How do I alphabetize a list of lines?
Paste your lines into the tool, pick alphabetical mode, and choose case-insensitive if you want the traditional A-Z order (treating a and A as equivalent). Click copy to get the sorted result. Works for any number of lines from 2 to hundreds of thousands.
▶What is natural sort and when should I use it?
Natural sort treats embedded numbers as numbers for comparison order. So item-2, item-10, item-100 sort in numeric order (item-2, item-10, item-100) instead of lexicographic (item-10, item-100, item-2). Use natural sort for lists of file names with numbers, version strings, or any case where numbers should be interpreted as numbers.
▶Can I sort numbers by value instead of as text?
Yes, use numeric sort mode. This treats each line as a number and sorts by value: 9, 42, 100, 300 instead of the lexicographic 100, 300, 42, 9 (which puts strings starting with 1 before strings starting with 9). Non-numeric lines are either moved to the end or flagged depending on your setting.
▶How do I remove duplicate lines?
Sort first, then enable the deduplicate option. Adjacent equal lines are collapsed into one. If you need to preserve original order while removing duplicates (keeping first occurrence only), use the separate Remove Duplicate Lines tool which uses a Set-based approach.
▶Is it case-sensitive by default?
Case-insensitive by default because that matches what most people mean by "alphabetize". Toggle case-sensitive mode if you need uppercase letters to sort before lowercase (useful for some programming conventions where constant names go before variable names).
▶Does sorting preserve blank lines?
By default, blank lines move to the top (because empty string comes first lexicographically). Enable the "skip blank lines" option to drop them from the output, or "preserve blanks" to keep them in place regardless of sort.
▶What is the largest list I can sort?
Tested up to a million lines in modern browsers with smooth performance. Beyond that you may hit memory limits in the browser tab — split the list into chunks, sort each, and merge if needed. For daily use the limit is whatever you can paste into a browser.
▶Does the tool support non-English alphabets?
Yes. Pick a locale in the options (German de-DE, Swedish sv-SE, Japanese ja-JP, Arabic ar, etc.) and sorting follows that language’s conventions. The browser’s Intl API supports over 100 locales with correct collation rules.
Additional resources
- MDN Intl.Collator — Browser API for locale-aware string comparison used in this tool.
- Unicode Collation Algorithm — Full specification of how Unicode text should be sorted, implemented by Intl.Collator.
- Wikipedia — Natural sort order — Background on natural sort and why it matters for human-readable ordering.
- Fisher-Yates shuffle — The algorithm used for uniformly random shuffle of lines.
- GNU sort manual — Unix sort command documentation — a powerful alternative for CLI workflows.
Related tools
All Text ToolsAdd Line Numbers
Prepend line numbers to every line of text with configurable starting number, padding width, and separator.
Case Converter
Convert between upper, lower, title, camel, snake, kebab, Pascal, CONSTANT cases
Find and Replace
Find and replace text with regex support, case sensitivity, whole-word matching, and preview of all changes before applying.
Line Counter
Count lines in text with separate totals for blank lines, non-blank lines, words, characters, and paragraphs for detailed statistics.
Remove Duplicate Lines
Remove duplicate lines from text with case-sensitive or case-insensitive matching, preserving original order or sorting the result.
Remove Line Breaks
Remove line breaks from text, convert to spaces, or keep paragraph breaks while flattening unwanted newlines.
Learn more
Explore more tools
200+ free tools that run in your browser.
Browse all tools →