Sort Lines: Sort Text Alphabetically Online

0
Words
0
Characters
0
No spaces
0
Lines
0
Paragraphs
0
Sentences
0 min
Reading time
Lines to sort
Sorted output

Paste a list, pick an order, get it sorted. Case-sensitive or not, ascending or descending, with natural sort for filenames and version strings.

What is the sort lines tool?

Sort Lines takes a block of text, splits it on line breaks, sorts the lines and hands you the result, free and in your browser. There is no signup, and the text is never uploaded.

It is the equivalent of running sort on the command line, except you do not have to fight with LC_COLLATE, the way macOS ships an older BSD sort, or the fact that Windows does not have sort at all unless you install Git Bash. Five buttons cover the cases that come up: A → Z and Z → A, a case-insensitive A → Z (Aa), plus Reverse and Shuffle. Numbers inside a line are always compared as numbers, so file2 comes before file10.

If you have ever pasted a list of dependencies into package.json and wondered why npm reordered them on the next install, sorting the keys A → Z here gets you close to the alphabetical order npm writes, so the next install has less to reshuffle. Sorting is also the trick for checking two lists against each other: sort both, then compare the two texts side by side and only the real differences stay highlighted.

How the sort works

Under the hood the tool uses the browser's Intl.Collator API. That gives you a Unicode-aware compare function the way the Unicode Collation Algorithm (UTS #10) defines it, not a raw codepoint compare. The practical difference: Intl.Collator knows that é sorts next to e, that German ß compares equal to ss at the primary level, and that uppercase and lowercase only differ at the tertiary level.

Lexicographic sort and locale-aware sort are not the same thing. A pure codepoint sort (what LC_ALL=C sort gives you) puts every uppercase letter before every lowercase letter, because A is U+0041 and a is U+0061. A Unicode default-collation sort interleaves them: A < a < B < b < C. Every button here uses the locale-aware order, because it matches what people expect when they hit Sort A-Z in Excel or Google Sheets. Plain A → Z still tells case apart and puts a just before A; A → Z (Aa) treats them as equal. For raw codepoint order, LC_ALL=C sort on the command line is the right tool.

Natural sort is always on. file2.log comes before file10.log because the embedded numbers are compared as numbers, not character by character. Wikipedia has a clean explanation of natural sort order if you want the background. The implementation uses Intl.Collator's numeric: true option, the same idea behind the filename order in Finder, Windows Explorer, and GNU sort -V use.

How to sort lines in three steps

One pane in, one pane out. The whole thing runs locally; close the tab and your text is gone.

  1. 1

    Paste your lines

    Drop your list into the editor, one item per line. CRLF and LF endings both work, and the output uses LF. A newline at the very end of the list stays at the end. The Sample button fills the editor with a small mixed list, including file2 and file10, if you want to see every button in action first.

  2. 2

    Click a sort button

    A → Z sorts ascending and keeps upper and lower case apart; Z → A is the same order reversed; A → Z (Aa) ignores case. Numbers inside lines always sort by value. Reverse flips the current order without sorting, and Shuffle puts the lines in random order.

  3. 3

    Copy the sorted result

    The result lands in the output pane as soon as you click, and your input stays put, so you can try another order. Copy puts the result on the clipboard; Download saves it as a .txt. To drop repeated lines as well, run the list through Remove duplicate lines first.

Everyday uses for sorting lines

Sorting an email list before a campaign send

Marketing pastes a CSV of subscriber emails into the campaign tool, but the list arrived in signup order. Sort it with A → Z (Aa) first, since email addresses are case-insensitive in practice, then dedupe it. The campaign tool's import will be faster and you will spot a typo'd domain like gmial.com immediately because it sits next to the legitimate gmail.com block.

Alphabetising CSS class names or HTML attribute order

Some teams enforce alphabetical class names in class="..." attributes so PR diffs stay clean. Paste the value, sort, paste it back. The same trick works for HTML attribute ordering when a linter complains, or for sorting Tailwind utility classes by hand when you do not have prettier-plugin-tailwindcss installed in the repo.

Sorting a .gitignore so future PRs diff cleanly

A .gitignore that everybody appends to becomes a junk drawer. Sort it alphabetically once, commit that, and from then on additions land in obvious places and the diff makes sense to reviewers. The same applies to .dockerignore, .eslintignore, and the files array in tsconfig.json when teams keep one.

Cleaning up a TODO list pasted from chat

Slack and Discord paste lists with weird ordering, half-empty lines, and duplicates from people who said the same thing twice. Run it through the duplicate-line remover, paste the result here and sort. Blank lines collect at the top, where they take one keystroke to delete, and you get a clean ordered list for your task tracker.

Sorting a list of country, airport, or currency codes

ISO 3166 country codes, IATA airport codes, ISO 4217 currency codes: these all live in lookup files that benefit from being sorted. Natural sort changes nothing here because the codes are fixed-width, but case does, because some sources mix USD with usd: A → Z (Aa) keeps them together. Sort, dedupe, paste back into the lookup table.

Sorting a list of package.json dependencies

package.json dependency keys are alphabetised by npm 7+ on every install, but if you are editing on a project still pinned to npm 6 (or yarn 1) the order will not change automatically. Paste the dependency keys, sort A-Z, and paste back. Your next PR will not have a 200-line reorder commit on top of the actual change.

Sort lines quick reference

A short cheat sheet for the sort options this tool exposes and the edge cases they cover.

TopicWhat this tool does
Lexicographic vs collation Lexicographic (codepoint) sort orders by raw Unicode value: A (U+0041) before a (U+0061). Collation sort follows the Unicode Collation Algorithm and interleaves cases. Every button here uses collation; for codepoint order use LC_ALL=C sort.
Case sensitivity A → Z (Aa) is case-insensitive: apple, Apple, and APPLE compare equal and keep their input order. A → Z and Z → A compare case at the tertiary collation level, so a sorts just before A, and both sort before b.
Natural sort Always on: file2 < file10 because 2 and 10 are compared as numbers. A plain character sort would put file10 first, since 1 (U+0031) is less than 2 (U+0032). It matters for filenames, version strings, and any list with embedded numbers.
Locale awareness Sort follows your browser's locale, so é orders next to e and accented letters sit with their base letter instead of after z. The unix sort command does the same thing if LC_COLLATE is set; LC_ALL=C sort falls back to codepoint order, which is faster but treats accents as alien letters.
Blank-line handling Empty lines sort before any non-empty line in A → Z, so they cluster at the top. Nothing removes them here. A newline at the very end of the input stays at the end of the output instead of turning into a blank first line.
Stability The sort is stable: lines that compare equal under your settings keep their original relative order. This matters when you sort by a prefix or under case-insensitive mode and want the input order preserved within a tie group. Both V8 (Chrome, Edge, Node) and SpiderMonkey (Firefox) guarantee stable Array.prototype.sort since 2019.
Line endings (LF vs CRLF) Input is split on \r\n, \n, and \r. Output is joined with \n by default so it pastes cleanly into Linux and macOS workflows. If you need CRLF for a Windows tool, paste the result into a Windows-aware editor and save with the line ending you want.
Encoding Input is treated as UTF-8 (text in the browser is already decoded). Files loaded with Upload have a leading byte order mark removed; one that arrives in pasted text stays attached to the line it started on.

Sort lines: frequently asked questions

What is the default sort order?

Locale-aware ascending, using the browser's Intl.Collator. That puts a next to A and b next to B, the way Excel and Google Sheets sort, rather than raw codepoint order where every uppercase letter comes before every lowercase one. A → Z keeps the two cases apart (a, then A); A → Z (Aa) treats them as equal. There is no codepoint-order button; LC_ALL=C sort on the command line gives you that.

Is the sort case-sensitive or case-insensitive?

Your pick. A → Z (Aa) is case-insensitive: Apple, apple, and APPLE compare equal, so they cluster together in their input order (the sort is stable). A → Z and Z → A are case-sensitive: the same three are distinct values, ordered by the Unicode default collation's tertiary level, which puts lowercase first. Either way, words still sort alphabetically first and case only breaks ties.

Does it support natural sort for filenames like file2 before file10?

Yes, on every sort button. Embedded numbers are compared as numbers, so file2.log comes before file10.log, and v1.9 comes before v1.10. The implementation is the numeric: true option on Intl.Collator, which gives the same kind of order macOS Finder and Windows Explorer show for filenames.

Can I sort in reverse (Z to A)?

Yes. Click Z → A. It sorts with the comparison flipped rather than reversing a sorted list, so lines that compare equal keep their original relative order. That matters when you are sorting on a partial key like the first column of a TSV. If you only want the existing order turned upside down, with no sorting at all, use Reverse.

What happens to duplicate lines and blank lines?

Both are kept. Sorting is stable, so duplicates stay in their original relative order, and blank lines cluster at the top with A → Z because they sort before any non-empty line. A newline at the very end of your input is treated as the end of the last line, not as a blank line, so it stays at the end. To drop repeats, use Remove duplicate lines, which also has a dedupe-and-sort button.

Is there a size limit?

Up to about 100,000 lines runs sub-second in the browser. Past 500,000 lines you start to feel it, mostly because rendering the result pane (not the sort itself) gets expensive. For multi-million-line files, the unix sort command with LC_ALL=C sort -u file.txt is faster and runs out-of-core. The GNU coreutils sort manual covers the flags worth knowing.

Is it free, and do I need to sign up?

Free, and there is nothing to sign up for. Every sort button, plus Reverse, Shuffle, Copy and Download, works without an account. The only limit on list length is your browser: about 100,000 lines still sort in under a second. Ads on the page pay for the hosting, so there is no paid tier either.

How is this different from sorting in Excel or the command-line sort?

No spreadsheet to open and no terminal to remember the flags for. In Excel you select a column, open Data, choose Sort, and hope you did not leave a header row in the selection. Here you paste and click. Versus the unix sort command, you skip the LC_COLLATE wrangling and the fact that Windows has no sort by default; and the Remove duplicate lines tool next door does what sort -u does, with nothing uploaded.

Is my text private, and is anything uploaded?

Nothing is uploaded. The split, the compare, and the join all happen in your browser; the text never touches a server, gets logged, or runs through any third-party service. You can paste a list of customer emails, internal hostnames, or anything else sensitive and close the tab without leaving a trace. If you want to check, open your browser's DevTools, watch the Network tab, and you will see no outbound request when you click a sort button.

Does sorting change my lines, or just reorder them?

It only reorders them. The text on each line is left exactly as you pasted it, including any leading or trailing spaces, so a line never gets trimmed, re-cased, or rewritten by the sort itself. Nothing is dropped either: the output holds every line you put in, same characters, just in a new order.

Does it work offline and on my phone?

Both. Because it is client-side JavaScript with no server call, once the page has loaded you can go offline and it keeps sorting; some people bookmark it for exactly that. On a phone the input and output stack vertically and the buttons stay reachable with a thumb, so pasting a list from a message and sorting it works fine on a small screen, even if a long list is easier to scan on a laptop.

Privacy and how this works

Your text never leaves your browser. Splitting, comparing and joining all happen locally, and nothing you paste is logged. The compare itself is the browser's native Intl.Collator, which implements the Unicode Collation Algorithm (UTS #10). If you want background reading, Wikipedia has a solid overview of sorting algorithms generally.