Free Line Sorter

Sort, reverse, deduplicate, or shuffle lines of text.

No data leaves your device
0 lines

Sort Mode

0 lines

About Line Sorting

Line sorting arranges text by comparing each line according to a chosen order. Alphabetical sorting is useful for lists, glossaries, and directories. Numeric sorting treats each line as a number and orders by value. Length-based sorting groups short and long entries together, which helps with formatting and layout tasks.

This tool also lets you remove duplicate lines, strip empty lines, trim whitespace, reverse the order, or randomly shuffle lines. All processing is instant and runs in your browser.

Common Uses

Frequently Asked Questions

How does numeric sorting work?

Numeric sorting extracts the leading number from each line and orders by that value. Lines that don't start with a number are sorted to the end. This means "9 items" comes before "10 items" (unlike alphabetical sort, where "10" would come before "9").

What does "Remove duplicates" do?

It removes lines that appear more than once, keeping only the first occurrence. When combined with "Case insensitive", lines that differ only in capitalization are also treated as duplicates.

Is the shuffle truly random?

The shuffle uses the Fisher-Yates algorithm with Math.random(). It is suitable for casual use like randomizing lists or drawing names. It is not cryptographically secure · for security-sensitive randomness use a dedicated tool.

What is line sorting?

Line sorting is the operation of reordering the rows of a text file or list according to a chosen rule. The rule can be lexicographic (compare characters left to right by their Unicode code point), numeric (extract a leading number and compare values), length-based (compare character counts), or random (a Fisher-Yates shuffle that produces a uniformly random permutation). Each rule answers a different question about your data.

This tool exposes eight sort modes (A to Z, Z to A, numeric ascending, numeric descending, shortest first, longest first, shuffle, reverse) plus four toggleable options (case-insensitive, trim whitespace, remove duplicates, remove empty lines). The combinations cover the everyday list-cleaning workflows that used to require a Bash one-liner with sort, uniq, awk and a shell pipeline. Now you paste the lines, click a mode and a few checkboxes, and read the result.

All computation happens in your browser using JavaScript's built-in Array.prototype.sort, which uses TimSort (a hybrid of merge sort and insertion sort, stable and worst-case O(n log n)) in V8, JavaScriptCore and SpiderMonkey since 2018. For lists under a million lines, the operation completes faster than the time it takes you to release the mouse button.

What is inside the sorter

The interface stacks three controls: an input textarea where you paste your lines, a row of eight mode buttons that highlight the active selection, and a row of four checkboxes for the dedup-and-trim options. Below them sits the Sort Lines action button, which produces the read-only output textarea and updates the line counter underneath.

The line counters above and below the input and output let you sanity-check the operation at a glance: if you started with 1,234 lines and ticked Remove Duplicates, the output count tells you immediately how many duplicates were dropped. This shortcut is faster than writing a one-off Python or AWK script for the same task.

Three actions wrap the bottom: Copy Result writes the output to your clipboard via the Clipboard API, Download .txt saves a UTF-8 text file with LF line endings, and Clear empties both textareas. No history is kept, no settings persist, and refreshing the page returns the tool to its default A-to-Z state.

History and background

Hollerith punch-card sorters (1890)

Herman Hollerith's punch-card sorter, built for the 1890 US Census, mechanically dropped each card into one of 12 bins based on the position of a punched hole. Operators ran the cards through the sorter multiple times, once per digit, to produce a full numeric sort. The technique was called radix sort, and it underpinned business computing for the next 60 years. IBM, founded as the Computing-Tabulating-Recording Company in 1911, grew directly out of Hollerith's machines.

John von Neumann describes merge sort (1945)

In a 1945 internal report on the EDVAC, John von Neumann described merge sort, the first algorithm written for a stored-program computer. The idea is recursive: split the list in two, sort each half, then merge the two sorted halves by repeatedly taking the smaller front element. Merge sort remains a textbook example of divide-and-conquer and is the basis of TimSort, the algorithm V8 uses for Array.prototype.sort today.

Tony Hoare invents quicksort (1959)

Tony Hoare, then a 25-year-old visiting Moscow State University to learn Russian, designed quicksort in 1959 while trying to sort a list of Russian words against an English dictionary. The algorithm picks a pivot, partitions the list around it, and recurses on each side. Average case is O(n log n), worst case O(n squared), but in practice it outperforms merge sort due to cache locality. Hoare won the Turing Award in 1980.

J.W.J. Williams introduces heapsort (1964)

J.W.J. Williams published heapsort in Communications of the ACM in 1964. The algorithm builds a binary heap (a tree where each parent is at least as large as its children) and repeatedly extracts the root. Guaranteed O(n log n) in both average and worst case, no extra memory, but cache-unfriendly. Heapsort is the worst-case fallback inside C++'s std::sort (Introsort, 1997).

ASCII fixes the sort order (1963 to 1967)

ASCII, ratified in 1963 and revised in 1967, assigned codes 48 to 57 to digits 0 to 9 and 65 to 90 to uppercase A to Z. The convention that 0 sorts before 9 sorts before A sorts before Z (and that uppercase sorts before lowercase) is baked into every default lexicographic sort the world has produced since. This is why "Apple" sorts before "apple" and why "10" sorts before "9" when you compare strings character by character.

Unicode Collation Algorithm (1996)

The Unicode Consortium published the first Unicode Collation Algorithm (UCA) in 1996, codified as UTS #10. UCA gives every code point a multi-level weight (primary, secondary, tertiary) so that sorting can be locale-aware: in German, ä can sort with a or after z depending on context; in Swedish, å sorts after z; in Spanish, ñ sorts after n. JavaScript's Intl.Collator (2014) wraps UCA and is what powers locale-correct list sorting on the web.

Practical workflows

Alphabetizing a list of names

You have a class roster, attendee list, or contact dump pasted from a spreadsheet column. Paste, tick Case insensitive (so "alice" and "Alice" sort together), click A to Z. The output is ready to copy back into the spreadsheet or paste into an email's BCC line. Trim Whitespace catches the stray spaces that come from copy-paste artifacts.

Deduplicating log entries

You exported 5,000 error messages from a server log and want to know the distinct ones. Paste, tick Remove duplicates, click A to Z. The output count tells you how many unique errors exist. Combine with Trim Whitespace if log lines have variable indentation.

Drawing names for a lottery or raffle

Paste the contestant names, one per line. Click Shuffle. The first line of the output is your winner, the second is the runner-up, and so on. The Fisher-Yates implementation uses Math.random, which is statistically uniform but not cryptographically secure. For prize draws with legal implications, run the shuffle on a server using a CSPRNG.

Preparing a CSV column

When a CSV file has unsorted product SKUs or customer IDs in a column, copy the column into a text editor, paste here, sort numerically, and paste back. The numeric mode handles SKUs like "9", "10", "100" correctly (lexicographic would order them 10, 100, 9, which is rarely what you want).

Comparing two lists for missing items

Sort both lists with the same options (A to Z, Case insensitive, Trim Whitespace). Paste them side-by-side into a diff tool. Items that appear in one list but not the other become obvious. This is faster than manually scanning unsorted lists and works even when both lists have thousands of entries.

Sorting a backlog or todo list

When you write a todo list in a plain text editor and want it back in priority or alphabetical order, paste into the sorter. Use Longest First to surface multi-step tasks at the top, or Shortest First to clear easy wins first. Reverse Order is useful when the original list was already sorted but in the wrong direction.

Common pitfalls

Lexicographic vs numeric sort

Default A-to-Z sorts compare strings character by character, so "10" comes before "9" because "1" comes before "9" in ASCII. For numeric data, use the Numeric mode instead. For mixed alphanumeric data like "file2.txt" vs "file10.txt" (natural sort), this tool does not support natural sort directly. You can fake it by zero-padding numbers before sorting.

Case sensitivity defaults to on

By default the sort is case-sensitive: "Apple" sorts before "apple" because uppercase A (65) comes before lowercase a (97) in ASCII. If you want case-insensitive sort (alphabetical without regard to capitalization), tick the Case insensitive checkbox before clicking Sort Lines.

Trailing whitespace breaks dedup

"apple" and "apple " (with trailing space) are different strings, so dedup keeps both. Always tick Trim Whitespace alongside Remove Duplicates when dealing with pasted data, otherwise the dedup count will be inflated by what look like identical lines.

Locale-aware sorting is not supported

This tool uses default Unicode code-point ordering, which is correct for English and many European languages but not for German (ä, ö, ü), Swedish (å, ä, ö), Spanish (ñ), or any script with collation rules. For locale-correct sorting, use a spreadsheet or a programming language with Intl.Collator support.

Stable sort is guaranteed since 2019

Array.prototype.sort became stable in all major browsers starting with Chrome 70 (2018) and Firefox 65 (2019). Before that, equal elements could be reordered unpredictably, which broke any workflow that depended on insertion order. This tool relies on the modern stable guarantee, so equal lines stay in their original relative order.

Unicode normalization affects equality

The character é can be encoded as a single code point (U+00E9) or as e plus combining acute accent (U+0065 U+0301). They look identical but are different byte sequences, so dedup will not match them. If your data mixes both forms, normalize with NFC in a programming language first, or expect duplicates to survive the dedup pass.

Privacy and data handling

Every line you paste is sorted in your browser by a small JavaScript function. No data leaves your device. We do not log inputs, store outputs, run analytics tied to the text content, or load third-party SDKs that could read the textareas. The Copy Result and Download .txt buttons interact with your operating system through standard user-gesture APIs (Clipboard API and the <a download> trick) and are not visible to outside parties.

Once the page is loaded, the tool works offline. You can disconnect from the network, open in a private window, run inside a corporate sandbox, or use airplane mode on a flight, and the sort will still complete. This makes the tool safe for confidential client lists, internal SKUs, and any data that should never touch a third-party server.

When not to use a line sorter

Sorting a spreadsheet column with related cells

If column A holds names and column B holds matching email addresses, copying only column A here and sorting will desynchronize the row relationship. Use the spreadsheet's built-in sort that moves entire rows together. Line sorting is for standalone, row-independent text.

Very large datasets (millions of lines)

The tool keeps the entire input and output in memory and runs synchronously, which can freeze the browser tab on multi-million-line inputs. For datasets of that size, use a command-line sort (Unix sort, sort -u, sort -n) which handles arbitrarily large files via external merge sort.

Real-time streaming data

If new lines arrive every second (such as a live log feed or a websocket stream), this tool cannot keep up. It is designed for batch processing of static text. For streaming sort use a database with a sorted index, or a programming language with a priority queue.

Structured data (JSON, CSV with quoting)

JSON arrays, CSV files with embedded commas inside quoted fields, or XML elements are not safe to sort as plain text because their delimiters span multiple lines. Use a JSON-aware sorter, a CSV parser, or jq for structured-data sorting.

More questions

Which sort algorithm does the tool use?

The tool uses the browser's built-in Array.prototype.sort, which is TimSort in V8 (Chrome, Edge, Node.js since 2018) and a custom merge sort in SpiderMonkey (Firefox). Both are stable, O(n log n) worst case, and optimized for partially-sorted real-world data. You almost certainly cannot beat them with a custom JavaScript implementation.

Can I sort by locale (German, Swedish, Chinese)?

Not in this tool. We use default Unicode code-point ordering. For locale-aware sorting (Swedish å after z, German ß as ss, Spanish ñ after n), use a spreadsheet with locale settings, or JavaScript's Intl.Collator in a custom script. The tool is intended for English-default workflows.

How random is the Shuffle option really?

The shuffle uses the Fisher-Yates algorithm (Knuth 3.4.2) with Math.random as the entropy source. Math.random in modern browsers uses xorshift128+ (Chrome since 2015), which is statistically uniform and passes randomness tests, but it is not cryptographically secure. For prize draws or anything with legal weight, use crypto.getRandomValues or a server-side CSPRNG.

Is there a maximum number of lines?

No hard limit. The tool comfortably handles 100,000 lines on a mid-range laptop. At 1 million lines, expect a one-to-three second pause while the browser does the sort. Above that, the textarea itself becomes the bottleneck, and the tool may briefly hang the tab. Use a command-line tool for very large datasets.

Why does my numeric sort put "1.5" between "1" and "2"?

Numeric sort parses the leading number using parseFloat, which recognizes decimal points (1.5), scientific notation (1e3), negatives (-5), and trailing units ignored after the digits. If the result is not a number, the line goes to the end. This behavior matches most user expectations but can surprise you with mixed integer-and-decimal lists.

Will the sort modify my original input?

No. The input textarea is untouched. The sorted output appears in a separate read-only textarea. You can sort the same input multiple times with different modes or options without losing the original. The Clear button is the only way to wipe the input, and it asks for no confirmation, so use it deliberately.

Related Tools