Sort Lines

Sort lines alphabetically, by length, numerically, or randomly. Reverse order supported.

100% private

Sort lines of text alphabetically (with optional locale-aware comparison), numerically (handles negative numbers and decimals), or by line length — ascending or descending. Useful for ordering a long list of names, tidying a config file for diffing, or arranging URLs before a bulk import. Shuffle mode is also there for randomising a queue. The sort runs as a single Array.sort in your tab, so even big lists stay private to the browser.

Sorted in your browser — your text is never uploaded.
1 lines • 0 chars
Sort Options
Runs right inside your browser tab. No uploads. Your files stay private.

How Sort Lines Orders Text

Sort Lines splits the input on newline characters, applies a comparator chosen from the eight sort modes (alphabetical, length, numeric, word-count, natural, random, reverse, column), and joins the result back with newlines. The underlying engine is JavaScript's built-in Array.prototype.sort, which the V8 and SpiderMonkey teams implement as a stable Timsort variant. Since the 2019 ECMAScript spec, sort stability is guaranteed across browsers, so equal keys keep their original relative order.
Alphabetical mode uses String.prototype.localeCompare with no explicit locale, so collation follows your browser's resolved default locale (for most visitors that is English dictionary order: a before A in case-sensitive mode, both equivalent in case-insensitive mode). Non-ASCII letters are ordered per that system locale rather than a locale you pick here. This is still more correct than a naive Unicode code-point comparison, which would put 'Z' (U+005A) before 'a' (U+0061) and break for any non-ASCII text.
Natural sort handles strings that mix letters and digits — 'file2' before 'file10' — by chunking each line into runs of digits and runs of non-digits, then comparing chunk-by-chunk. Numeric chunks are compared as numbers, alphabetic chunks via localeCompare. This matches Windows Explorer's file ordering and is the only correct option for version strings, paginated filenames, and ticket numbers.
Numeric mode extracts the first number it can parse from each line (matching the regex /-?\d+(?:\.\d+)?/) and sorts on that. Lines with no parseable number sort as zero and clump together. This is useful for sorting log lines by timestamp prefix or CSV rows by a specific column once you have isolated it. For full numeric precision use the column mode with a delimiter that matches your data.
Column mode splits each line on a chosen delimiter (tab, comma, pipe, or custom), takes the nth field, and uses that as the sort key. The remaining fields ride along — only the sort key is extracted, not the line contents. This is the right tool for sorting CSV-like text by a non-first column without round-tripping through a spreadsheet.
Random mode uses the Fisher-Yates shuffle backed by Math.random(). For small lists this is fine. If you need cryptographically random shuffling (for raffles or unbiased trial assignment) the underlying Math.random is not suitable — use crypto.getRandomValues in a small script instead. The shuffle is in-place on a copy, so the original input is preserved.
Empty-line handling is independently configurable: keep, remove, push to top, or push to bottom. This matters when sorting blocks of text where blank lines are paragraph separators. The deduplicate option uses a Set to remove every repeated line, keeping the first occurrence, regardless of sort order — so duplicates are collapsed even in random mode where they are not adjacent. Combining sort with dedupe gives the same result set as Unix `sort -u`.

Common Use Cases

01

Filename ordering

Use natural sort so 'screenshot-2.png' comes before 'screenshot-10.png' instead of after, matching Finder and Explorer behavior.

02

Version list sorting

Sort semver tags like v1.10.0 and v1.9.0 with natural sort so 1.10 comes after 1.9 rather than before.

03

CSV column sort

Pick a delimiter and column index to sort comma- or tab-separated rows by a non-first field without opening a spreadsheet.

04

Log line ordering

Sort log dump lines numerically by timestamp prefix or alphabetically by severity to consolidate scattered entries.

Frequently Asked Questions

Natural sort treats runs of digits as numbers. 'file2' has a numeric chunk of 2, 'file10' has a numeric chunk of 10, so file2 sorts first. Alphabetical sort compares character-by-character — '1' (U+0031) comes before '2' (U+0032), so file10 sorts before file2. Natural sort is the standard choice for filenames and version strings.
It uses String.prototype.localeCompare with no explicit locale, so it honors whatever collation your browser resolves as its default — typically the language from your OS settings. For most visitors that is English dictionary order. Non-ASCII letters (German ß, Swedish å ä ö, Czech č š) sort according to your system locale, not a locale you can choose in the tool, so a visitor on an English system will see English ordering even for non-Latin text.
Yes. Modern JavaScript engines implement Array.prototype.sort as a stable Timsort variant, which has been the spec requirement since ES2019. Equal keys preserve their original relative order, which matters when you sort by one column and want the secondary order to remain the input order.
Each line is split on the delimiter you choose (tab, comma, pipe, or a custom string). The nth field becomes the sort key. The full line, including all other fields, is preserved in the output. If a line has fewer fields than the chosen index, it is treated as having an empty key and clumps at the start of the sorted list.
Yes. Enable the deduplicate option and a Set removes every repeated line, keeping the first occurrence — it does not depend on duplicates being adjacent, so it also works in random mode. Combined with sorting, the result set matches Unix `sort -u`. For order-preserving dedupe (without sorting), use the Remove Duplicates tool instead.
No. It uses a Fisher-Yates shuffle backed by Math.random(), which is fine for casual ordering but not for raffles, trial assignment, or anywhere bias matters. For cryptographic-grade randomness, generate the order with crypto.getRandomValues in a small script.
Configurable. By default, blank lines are removed. You can also keep them in their original positions, push them all to the top, or push them all to the bottom of the result. Keeping them in place matters for poetry-shaped input where stanzas are separated by empty lines you may want to preserve.
Only if you enable trimming, which strips leading and trailing whitespace from each line before comparison. Otherwise the lines are written to the output exactly as they appeared in the input — the comparison key may be normalized (case-folded, trimmed) but the displayed text is verbatim.
Sorting one hundred thousand lines completes in well under a second. The sort runs synchronously on the page's main thread, so very large inputs (around a million lines with locale-aware comparison) will briefly freeze the tab while it works — the UI is not responsive during that pass. For multi-million-line inputs, prefer command-line `sort`, which is faster and will not block a browser tab.
Because alphabetical mode compares character-by-character. The string '100' starts with '1' (U+0031) which is less than '2' (U+0032), so '100' sorts before '2' alphabetically. Use numeric mode to extract the leading number, or natural mode if the lines mix letters and numbers.
Maintained by the WebToolVerse teamLast updated Suggest an edit

Advertisement