Skip to main content

Text Sorter: Sort Lines Alphabetically or Numerically

Sort a list of text lines with the available ordering options. Review case, whitespace, and duplicate settings before copying the output.

Text Sorter workspace

Sort method

Standard alphabetical order

Input · 9 lines
Samples:
Output · 9 lines
apple
Apple
Banana
banana
cherry
date
Elderberry
fig
Grape

Eight Sort Methods

Alphabetical (A-Z, Z-A), numeric (ascending, descending — by first number in each line), length (shortest to longest, longest to shortest), reverse, and random shuffle.

Dedupe Built In

Optional deduplication runs before the sort. Keep-first preserves original ordering of survivors; keep-last keeps the most recent occurrence of each unique line.

Crypto-Strength Shuffle

Random shuffle uses Fisher-Yates with crypto.getRandomValues — every permutation is equally likely, suitable for fair lotteries and randomized A/B test cohorts.

100% Client-Side

All sorting happens in your browser. Lists may contain emails, customer IDs, or internal data — they never leave the page. Works offline once loaded.

Sort lines of text online: alphabetical, numeric, length, reverse, shuffle

Sort a list of text lines with the available ordering options. Review case, whitespace, and duplicate settings before copying the output. Text and numeric sorting answer different questions. Values such as 2, 10, and 100 can appear in different orders when treated as strings. Check leading zeros and identifiers before choosing numeric ordering, and keep an original copy if line order carries meaning.

How to use the text sorter

  1. Paste or type your list into the input pane, one entry per line, or load a sample.
  2. Pick a Sort method: alphabetical A–Z / Z–A, numeric ascending / descending, length, reverse, or random shuffle.
  3. Toggle Case-insensitive sort to merge Apple and apple instead of grouping all capitals first.
  4. Optionally enable Trim whitespace, Drop empty lines, or a Dedupe mode (keep first or keep last occurrence).
  5. Read the live counts (input lines, output lines, duplicates removed), then press Copy. Use Re-shuffle for a fresh random order.

How sorting works: code points, not locale collation

Alphabetical sort here compares two lines character by character using their Unicode code points — the same default behavior as JavaScript's built-in Array.prototype.sort. That means capital letters (code points U+0041U+005A) sort before all lowercase letters (U+0061U+007A), and accented characters like é (U+00E9) land after every plain ASCII letter. Turn on Case-insensitive to lowercase both sides before comparing, which merges the cases.

This tool does not use locale-aware collation (localeCompare) or the Unicode Collation Algorithm (UTS #10), so it will not reorder Swedish ä after z or fold æ the way a language-specific sort would. Numeric sort sidesteps the most common surprise — file10 sorting before file2 — by reading the first number in each line with parseFloat and comparing values, so negatives and decimals order correctly and lines with no leading number fall to the bottom.

Worked examples: input → output

Numeric ascending · mixed list

15 apples, banana, 3 carrots, dates → 3 carrots, 15 apples, banana, dates

Numbers sort by value (3 < 15); non-numeric lines fall to the bottom and sort among themselves.

Alphabetical A–Z · case-insensitive on

Banana, apple, Cherry, apple → apple, apple, Banana, Cherry

With case-insensitive off, all capitals (Banana, Cherry) would sort before any lowercase (apple).

Alphabetical + Dedupe keep-first

Sarah, Jin, Sarah, Marcus, Jin → Jin, Marcus, Sarah

Duplicates collapse first, then the survivors are sorted — output reports "2 duplicates removed".

Edge case · numeric sort on IP addresses

Numeric sort reads only the first octet, so 192.168.1.2 and 192.168.1.10 are treated as equal (both parse to 192) and keep their input order. For true IP ordering, zero-pad every octet (192.168.001.010) and use alphabetical sort instead.

When a line sorter saves real time

Use CaseWhy a Sorter Helps
Cleaning import listsDeduplicate email addresses, customer IDs, or contact lists before bulk-importing into a CRM or marketing tool.
Alphabetizing referencesSort bibliography entries, glossaries, FAQ items, or sitemap URL lists for consistent presentation.
Building random samplesShuffle a customer list to pick a random test cohort, or randomize a draft list of names for a fair lottery.
Sorting IPs / timestampsNumeric sort orders IP addresses or Unix timestamps correctly; alphabetic sort would produce confusing results.
Sanitizing user inputTrim trailing whitespace, drop empty lines, dedupe entries before counting or processing imported records.
Prioritizing by lengthSort form-field entries or feedback by length to spot suspicious one-character entries or runaway long ones.

Sorter Behaviors & Practical Tips

Numeric sort handles negative numbers and decimals correctly

parseFloat-based — "-15.7" sorts before "1.0" sorts before "100".

Mixed numeric/non-numeric lines: numbers come first

Lines without a leading number fall to the bottom and sort among themselves alphabetically.

Dedupe with "keep first" preserves original ordering of survivors

When you also sort, dedupe happens before the sort — the surviving lines then get reordered.

Trim whitespace before dedupe

Otherwise "apple" and "apple " count as different entries. Toggle both options together for cleanest results.

Random shuffle uses crypto-strength RNG

Same Fisher-Yates algorithm as our Password and Random Number generators — each permutation equally likely.

Four sort gotchas worth knowing

1. Alphabetical Sort of Numbers Is Wrong

"1, 10, 100, 2, 20, 3" — alphabetical sort places "10" and "100" before "2" because the character "1" precedes "2". Use numeric sort for any list with leading numbers.

2. Case-Sensitive Sort Splits Cases

Default JavaScript sort places ALL uppercase before ALL lowercase: "Apple, Banana, apple, banana". Toggle case-insensitive to merge them: "apple, Apple, banana, Banana".

3. IP Addresses Sort Awkwardly

Numeric sort uses ONLY the first octet. For true IP-order ranking, zero-pad each octet (192.168.001.010) and use alphabetical sort instead.

4. Trailing Whitespace Causes Phantom Duplicates

"email@x.com" and "email@x.com " sort as different lines AND survive dedup unless you trim. The defaults trim — turn that off only when whitespace matters.

Sort method reference

Eight methods, plus three independent cleanup options (case, trim, dedupe). This table maps each method to what it compares and when to reach for it.

MethodComparesBest for
Alphabetical A–Z / Z–AUnicode code points, optionally lowercasedNames, words, URLs, glossary entries
Numeric asc / descFirst number per line via parseFloatIDs, prices, ports, timestamps, ranked tasks
Length shortest / longestCharacter count of each lineSpotting stray one-character or runaway entries
ReverseNothing — flips current order, last line firstInverting logs or an already-sorted list
Random shuffleFisher–Yates with crypto.getRandomValuesFair lotteries, A/B cohorts, randomized draws

The natural-sort limit most sorters hide

Pure alphabetical sort is not "human" sort. Because comparison is by raw code point, a list of file2, file10, file1 sorts to file1, file10, file2file10 lands before file2 because the character 1 precedes 2. True natural sort (where file2comes before file10) needs localeCompare with { numeric: true }, which this tool deliberately does not apply to the alphabetical mode. The fix on this page: if your lines carry a leading number, switch to Numeric sort, which compares the embedded number as a value and gives you human ordering for free.

One more honest limit: the random shuffle is genuinely fair. It uses the Fisher–Yates algorithm — the one shuffle that makes every permutation equally likely — seeded by crypto.getRandomValues rather than Math.random, so it is suitable when statistical fairness actually matters.

Last updated: September 15, 2026 · Runs 100% in your browser — no uploads, tool input is not sent to Toolk.

Frequently asked questions

Why did file10 sort before file2 in alphabetical order?

Alphabetical mode compares raw Unicode code points, so the character 1 precedes 2 and file10 lands early — that is standard JavaScript sort behavior, not a bug. Switch to Numeric sort, which parses the leading number of each line with parseFloat and compares values, to get human ordering for numbered lists.

How fair is the random shuffle for giveaways or A/B assignment?

Genuinely fair: it applies the Fisher–Yates algorithm — the one shuffle where every permutation is equally likely — seeded by crypto.getRandomValues instead of Math.random, so it holds up when statistical fairness matters. Press Re-shuffle any time you want a fresh independent ordering.

Do the lists I sort get uploaded or logged anywhere?

No. Every method — alphabetical, numeric, length, reverse, and shuffle — plus dedupe and trimming run locally in your browser tab, so tool input is not sent to Toolk. Toolk's page analytics never receive your line content.

What should I do before sorting a messy imported list?

Run cleanup first: strip repeats with Toolk's duplicate line remover (/tools/remove-duplicate-lines) or this tool's built-in Dedupe (keep first keeps the earliest copy), enable Trim so phantom whitespace duplicates collapse, and drop empty lines — then apply your chosen sort method to the cleaned list.

Need a different tool?

Browse all 103 browser-based tools (103 currently marked free), or tell us what useful utility we should build next.

Browse all tools