Paste a list and sort the lines alphabetically, numerically or in natural order, where server-2 comes before server-10. The same pass can trim whitespace, drop blank lines and remove duplicates, and Copy Result puts the sorted list on the clipboard.
server-10.internal
server-2.internal
Server-1.internal
server-2.internal
db-primary
api-gateway
server-100.internal api-gateway
db-primary
Server-1.internal
server-2.internal
server-10.internal
server-100.internal Locale-aware, using Intl.Collator. Accented letters sort next to their base letter (é after e instead of after z). Digits are compared one character at a time, so 10 comes before 2.
Same collation, but runs of digits compare as numbers. Use Natural for file names, hostnames and labels with numbers in them. It gives img2, img10, img100 instead of img10, img100, img2.
Reads the number at the start of each line, including negatives, decimals and thousands separators such as 1,000. Lines that do not start with a number go to the bottom in A to Z order.
By length counts code points, so é counts as one character. Reverse order flips the list without sorting it. Shuffle runs a Fisher-Yates shuffle fed by crypto.getRandomValues, so every order is equally likely.
GNU sort follows your locale. With
LC_ALL=C it compares raw bytes, which puts every
uppercase letter before every lowercase one and pushes accented
characters past z. With a UTF-8 locale it behaves much like the A
to Z mode here. When a server and a laptop sort the same
list differently, check the locale first. Run
locale on both machines and compare
LC_COLLATE.
Every sort here is stable, so lines that compare equal keep their original order. This matters with Case-insensitive on, where Apple and apple tie, and with By length, where lines of the same length keep their order relative to each other.
const lines = ["server-10", "Server-2", "server-1", "api", "server-2", "db-primary"];
// Natural order, case-insensitive: server-1, Server-2, server-2, server-10
const natural = new Intl.Collator("en", { numeric: true, sensitivity: "base" });
console.log(lines.toSorted(natural.compare));
// Unique first, then sort (Set keeps the first copy of each line)
console.log([...new Set(lines)].sort(natural.compare));
// By length, longest first. Spread counts code points, not UTF-16 units.
console.log(lines.toSorted((a, b) => [...b].length - [...a].length));
// Numeric sort needs a comparator: the default sort compares strings
console.log(["10", "9", "100", "-1"].sort((a, b) => a - b)); // [ '-1', '9', '10', '100' ] toSorted() returns a new array and needs Node 20 or a current browser; use [...lines].sort() on older runtimes.
<?php
$lines = ["server-10", "Server-2", "server-1", "api", "server-2", "db-primary"];
// Natural, case-insensitive. sort() reindexes; natcasesort() keeps keys.
$natural = $lines;
sort($natural, SORT_NATURAL | SORT_FLAG_CASE);
echo implode("\n", $natural), "\n";
// Unique, then sorted
$unique = array_values(array_unique($lines));
sort($unique, SORT_NATURAL); // case-sensitive: uppercase sorts first
print_r($unique);
// By length in characters, not bytes
usort($lines, fn($a, $b) => mb_strlen($a) <=> mb_strlen($b));
print_r($lines); import re
import secrets
lines = ["server-10", "Server-2", "server-1", "api", "server-2", "db-primary"]
def natural_key(s):
# "server-10" -> ["server-", 10, ""] so the numbers compare as numbers
return [int(t) if t.isdigit() else t.casefold() for t in re.split(r"(\d+)", s)]
print(sorted(lines, key=natural_key))
print(sorted(set(lines), key=natural_key)) # unique, then natural order
print(sorted(lines, key=len, reverse=True)) # longest first
# Shuffle with a CSPRNG instead of the default Mersenne Twister
secrets.SystemRandom().shuffle(lines)
print(lines) Since ES2019, the spec requires Array.prototype.sort() to be stable, so lines that compare equal keep their original relative order. Python's sorted() and PHP 8's sort() are stable too. PHP 7 and older were not, so do not rely on tie order there.
This tool follows the specifications below. Read them when you need the exact normative wording, for example to settle an edge case between two implementations.
Paste the list, one item per line, and pick A to Z or Z to A in the Sort dropdown. The comparison is locale-aware (it uses Intl.Collator), so accented letters sort next to their base letter instead of after z.
Alphabetical sorting compares one character at a time, and the character 1 comes before 2. Pick Natural to compare runs of digits as numbers (file2 before file10), or Numeric to sort by the number at the start of each line.
Case only breaks ties by default: apple and Apple sit together, with the uppercase one first. Tick Case-insensitive to treat them as equal, which keeps their original order and makes Unique only treat them as duplicates.
It is a Fisher-Yates shuffle driven by crypto.getRandomValues with rejection sampling, so every ordering is equally likely. Shuffle Again draws a new order.
No fixed limit. The list is sorted in your browser tab, so the practical limit is your device's memory, and nothing is uploaded. For multi-gigabyte files, GNU sort on the command line is the better choice.
To drop repeats without reordering, use remove duplicate lines. The diff checker compares two sorted lists, the case converter normalizes the entries first, and the word counter tells you how long the list got.