Text Sorter
Paste lines below and choose a sort mode. Each line is treated as one item.
Why Sorting Lines by Hand Is a Productivity Trap
Anyone who has ever maintained a long list of product names, countries, error codes, or student roll numbers knows how quickly manual alphabetization falls apart. You move ten lines, miss one, move another, and suddenly the list that was supposed to save you time has cost you twenty minutes of squinting. A line sorter eliminates that entirely β paste, click, done.
What Does "Sort by Line" Actually Mean?
Most text editors treat a document as a stream of characters. When you want to reorder chunks of content, you need a tool that understands the newline character as a delimiter β splitting the input into discrete units, applying a comparison rule to each pair, and reassembling. That is exactly what a text line sorter does. Every newline creates one "item." The sort happens on those items, not on individual characters within a line.
A-Z vs. Case-Sensitive: The Difference Is Bigger Than You Think
In a case-insensitive A-Z sort, "Apple", "apple", and "APPLE" are treated identically β they land together wherever the letter A falls in the sequence. That is what most people expect and want for everyday lists.
Case-sensitive sorting follows ASCII (or Unicode) ordering instead, where uppercase letters have lower code points than lowercase ones. In practice this means every capital letter sorts before every lowercase letter. "Zebra" comes before "apple" because Z (code 90) is numerically smaller than a (code 97). This matters when you are sorting code identifiers, environment variable names, or file paths where casing is meaningful.
When to Use Length-Based Sorting
Sorting by character length has surprisingly practical applications that alphabetical sorting cannot cover:
- SQL query building: When constructing IN clauses manually, seeing the shortest values first helps spot accidental duplicates or truncated entries.
- UI label review: Designers often want to see all button labels ordered from shortest to longest to catch any text that might overflow its container.
- Password/key auditing: A security review of a list of tokens or hashes can quickly reveal suspiciously short entries that do not meet minimum length requirements.
- SEO keyword lists: Short-tail keywords (1-2 words) naturally surface at the top when you sort by length, separating them from long-tail phrases without any manual filtering.
Numeric Sort: Why It Is Not Just "Alphabetical with Numbers"
This is where a lot of generic text editors stumble. If you sort ["10", "9", "21", "3"] alphabetically, you get ["10", "21", "3", "9"] β because the character "1" sorts before "2", which sorts before "3". That is correct alphabetically but completely wrong if these are version numbers, prices, or quantities.
A true numeric sort converts each line to a floating-point number before comparing. The result is [3, 9, 10, 21] β which is what almost everyone actually wants when their list contains numbers. Mixed lists (some numeric, some not) are handled gracefully by placing numeric lines first (or last, depending on direction) and falling back to alphabetical comparison for non-numeric entries.
Duplicate Removal: A Hidden Use Case
Lists grow messy. You copy data from three spreadsheets, a colleague appends more rows, and a third person pastes the original again "just to be safe." The result is a list riddled with duplicates that sorting alone reveals but does not fix.
The duplicate removal option here works after sorting β meaning once items are in order, consecutive identical items are easy to detect and discard. The comparison can be case-sensitive or case-insensitive depending on your toggle, so "Error" and "error" can be treated as the same duplicate or as two distinct entries depending on your context.
Trimming Whitespace β The Invisible Problem
When text is pasted from spreadsheets, terminals, or web pages, invisible leading and trailing spaces often tag along. A line like " banana" sorts completely differently from "banana" β it lands near the top (spaces have a lower Unicode value than letters) even though they look the same on screen. Enabling the trim option strips those invisible characters before any comparison happens, so the sort behaves exactly as you would expect visually.
Real Scenarios Where This Tool Earns Its Keep
Developers use line sorting constantly β alphabetizing import statements (many style guides require this), ordering CSS properties, sorting config keys for cleaner diffs, or sequencing test case IDs numerically.
Writers and editors sorting character names, chapter titles, or bibliography entries alphabetically save significant time especially when a list has grown organically over months and is thoroughly disordered.
Data analysts working with exported CSVs that lack proper tooling can paste a single column into this sorter to quickly understand the range of values β are there 3 unique entries or 300?
Teachers and administrators sorting student names, assignment submissions, or grade entries by name or score no longer need Excel open just to run a basic sort on 40 lines.
What Happens to Blank Lines?
Blank lines sort to the very top in A-Z mode (empty string comes before any character) and to the very bottom in Z-A mode. If your list has intentional blank lines as visual separators, you probably want to remove them before sorting β which is exactly what the "ignore blank lines" option does. It filters out any line that is entirely empty (or becomes empty after trimming), so the sorted output contains only meaningful content.
The Stability Question
A "stable" sort preserves the original relative order of items that compare as equal. Modern JavaScript's Array.sort() is specified as stable in ECMAScript 2019 and later, and all current browsers implement it that way. This means if two lines are identical in the chosen sort key (for example, same length), they appear in the output in the same order they appeared in the input. For most practical uses this is exactly the right behavior β predictable, unsurprising, and consistent across browsers.