📊 Sort Lines
Sort lines alphabetically, numerically, or by length. Count lines too.
Sorted Lines
How to Sort Lines of Text
Paste your text into the input area above. Each line is treated as a separate item. Choose your preferred sort method from the dropdown and the tool instantly reorders the lines. Click "Copy Sorted Lines" to copy the result to your clipboard.
Sort Methods Explained
Alphabetical (A→Z / Z→A) sorts lines in dictionary order using Unicode code-point comparison. Numbers come before letters in ASCII order. This is ideal for sorting names, book titles, product names, or any text-based list where alphabetical order is meaningful. Enabling "Case insensitive" makes uppercase and lowercase letters sort together (the default behavior).
Numerical (1→9 / 9→1) sorts lines by their leading numeric value. The key difference from alphabetical sort is that "10" correctly comes after "9" (numerically), not before it (alphabetically, where "1" < "9" character-by-character). Always use numerical sort for numbered lists, dataset rows, or any list where lines start with numbers.
By Length (Shortest/Longest first) orders lines purely by their character count, ignoring content. This is useful for: organizing list items visually from short to long, finding the longest/shortest entries in a dataset, creating a word list sorted by word length, or identifying potentially truncated data entries.
Reverse Current Order flips the order of lines without any content-based sorting. The last line becomes first, the first becomes last, and all other lines shift accordingly. This is a simple way to reverse a chronological log, flip a list prepared bottom-to-top, or undo a previous reverse operation.
Shuffle / Randomize uses the Fisher-Yates algorithm to randomly reorder lines. Each click produces a statistically unbiased random permutation. Common uses: creating randomized quiz questions from a list, random sampling from a large list, or generating random orderings for experiments.
Practical Use Cases
- Organizing glossaries and indexes: Sort alphabetically to create a professional glossary, index, or bibliography for a document.
- Code formatting: Sort CSS properties alphabetically for consistency. Sort import statements in JavaScript or Python files. Sort configuration keys in JSON, YAML, or .env files. Many style guides (like Google's) recommend alphabetical imports.
- Data preparation: Sort exported CSV rows, database query results, or API response lists for easier manual review, or before importing into a spreadsheet.
- Deduplication workflow: Sort lines before running them through the Duplicate Line Remover — sorted lists make it easier to visually spot duplicates.
- Priority ranking: Sort tasks or items numerically by priority score. Sort bug tickets by severity number. Sort products by price (if prices are on their own line).
- Randomizing tests and surveys: Shuffle a list of questions to create multiple versions of a quiz with different question order, reducing copying between participants.
- Finding outliers: Sort by length to quickly spot unusually long or short lines in a dataset, which may indicate data entry errors or truncation issues.
Alphabetical vs Natural Sort
This tool uses lexicographic (alphabetical) sort for the alphabetical modes, not natural sort. Lexicographic sort compares strings character by character in Unicode code-point order. This means "file10.txt" sorts before "file2.txt" alphabetically, because "1" < "2" at the third character. If your data contains filenames, version numbers, or other strings with embedded numbers that should sort naturally ("file2" before "file10"), use the Numerical sort option or pre-process your data to zero-pad numbers before sorting.
Related Tools
- Duplicate Line Remover — Remove duplicate lines from your sorted output.
- Text Reverser — Reverse line order or individual characters.
- Find & Replace — Clean up or reformat lines before sorting.
- Whitespace Cleaner — Normalize whitespace before sorting to ensure accurate comparisons.
Frequently Asked Questions
What sort options are available?
You can sort lines Alphabetically (A-Z or Z-A), Numerically (1-9 or 9-1), by Line Length (shortest or longest first), Reverse current order (flip without sorting), or Shuffle/Randomize (random order every time).
Can I sort case-insensitively?
Yes! The "Case insensitive" toggle (enabled by default) makes the sort treat uppercase and lowercase letters equally. So "apple", "Apple", and "APPLE" will all sort together. Disable it for a strict Unicode code-point sort where uppercase letters come before lowercase.
Is my data stored on a server?
No — all line sorting takes place purely in your browser using JavaScript. Your text never leaves your device.
What is the difference between alphabetical and numerical sorting?
Alphabetical (lexicographic) sort compares characters left to right like a dictionary. In alphabetical sort, "10" comes before "9" because "1" < "9". Numerical sort compares the leading numeric value of each line, so "10" correctly sorts after "9". Always use numerical sort for lists that start with numbers.
What does Sort by Length do?
Sort by Length orders lines by their character count, not their content. "cat" (3 chars) comes before "elephant" (8 chars) when sorting shortest-first. This is useful for organizing things by complexity, creating visual rhythm in lists, or finding your shortest/longest items quickly.
What does Shuffle do?
Shuffle randomizes the order of lines using the Fisher-Yates algorithm (the standard unbiased shuffle algorithm). Each click produces a different random order. Useful for creating random quiz questions from a list, picking a random item, or randomizing playlist order.
Can I sort a numbered list and keep the numbers?
Yes — the sort operates on the entire line including any leading numbers or prefixes. If you have a numbered list like "1. Apple 2. Banana" and sort alphabetically, the numbers will move with their items. If you want to remove and re-add numbers after sorting, use Find & Replace to strip the numbers first.