Line sorter

Sort, deduplicate, and reverse lines in your browser. UTF-16 code unit order (not locale). Ignore case option for sorting and deduplication.

Sort, deduplicate, and reverse lines in your browser. Lines are split on LF after normalizing CRLF and CR; a trailing empty field from a final newline is dropped. Sort uses Array.prototype.sort with no compare function (UTF-16 code units — not localeCompare). Uppercase letters sort before lowercase (A is 65, a is 97). Ignore case compares toLowerCase() keys while preserving original casing. Unique keeps the first occurrence of each key via Set. Reverse calls reverse() without sorting. For case conversion, see /case-converter/. For Unicode normalization, see /unicode-normalize/. Nothing is uploaded.

Lines
Output

How it works

  1. Sort, Unique, and Reverse are buttons, not as-you-type. Copy writes the output. Nothing is uploaded.
  2. Lines are split after \r\n and \r become \n. A trailing empty field from a final newline is dropped. Internal blank lines stay. Lines are not trimmed.
  3. Sort uses Array.prototype.sort() with UTF-16 code unit order. Uppercase letters sort before lowercase (A is code unit 65, a is 97). Ignore case compares toLowerCase() keys while preserving original casing. Unique keeps the first occurrence of each key via Set. Reverse calls reverse() without sorting. Output is joined with LF.
  4. This is not localeCompare, not a natural/numeric sort, not Unix sort, and not a CSV column sorter. For case conversion, see /case-converter/. For Unicode normalization, see /unicode-normalize/.

Sort lines in Python and Node

The snippets below sort, unique, and reverse banana, Apple, apple, banana, and Cherry — the same lines this page documents. Node calls Array.prototype.sort with no compare function — the same ECMA-262 UTF-16 code-unit order as this page. CPython sorted compares Unicode code points. Those orders match for U+0000–U+FFFF and diverge for supplementary characters. Neither snippet is localeCompare, Unix sort, or a natural/numeric sort. For code units vs locale collation, see UTF-16 vs Locale Sort: Code Units vs localeCompare.

Node.js with Array.prototype.sort

sort() and reverse() mutate in place — copy with slice() first. Unique is new Set, same first-occurrence rule as this page. A leading surrogate (U+D800–U+DBFF) sorts before BMP characters in U+E000–U+FFFF, so \u{1F600} sorts before \uFFFD:

const lines = ['banana', 'Apple', 'apple', 'banana', 'Cherry'];

lines.slice().sort().join('\n');
// "Apple\nCherry\napple\nbanana\nbanana"

[...new Set(lines)].join('\n');
// "banana\nApple\napple\nCherry"

lines.slice().reverse().join('\n');
// "Cherry\nbanana\napple\nApple\nbanana"

Python with sorted

sorted(lines) matches this page on the BMP lines below. dict.fromkeys keeps first occurrence like Set. Prefer splitting on CR/LF yourself — str.splitlines() also splits U+2028 and U+2029, which this page leaves in the line. By code point, \U0001F600 sorts after \uFFFD:

lines = ['banana', 'Apple', 'apple', 'banana', 'Cherry']

'\n'.join(sorted(lines))
# 'Apple\nCherry\napple\nbanana\nbanana'

'\n'.join(dict.fromkeys(lines))
# 'banana\nApple\napple\nCherry'

'\n'.join(reversed(lines))
# 'Cherry\nbanana\napple\nApple\nbanana'

Ignore-case sort on this page compares toLowerCase() keys and keeps original casing — Node lines.slice().sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase())) is locale collation, not this page. Use a UTF-16 / code-point compare on the lowercased keys instead. Python sorted(lines, key=str.lower) matches this page on the BMP sample (Apple, apple, banana, banana, Cherry). str.casefold maps ß to ss; this page leaves ß. "10" still sorts before "2". Case mapping lives on the case converter; normalize first on the Unicode normalizer.

Sort lines in the shell

Sort on this page is Array.prototype.sort with no compare function — UTF-16 code-unit order, not localeCompare and not Unix sort. POSIX sort reads a file or stdin and compares with the current LC_COLLATE. LC_ALL=C is byte order; on banana, Apple, apple, banana, and Cherry that matches this page (Apple, Cherry, apple, banana, banana). A UTF-8 locale uses strcoll and can regroup letters — GNU en_US.UTF-8 prints apple, Apple, banana, banana, Cherry. echo appends a newline, so use printf to feed the same five lines. sort writes a trailing newline after the last line; this page joins with LF and does not.

GNU sort (Linux)

Coreutils sort defaults to the process locale. Pass LC_ALL=C for the byte order this page uses on ASCII:

# Byte order (same ASCII order as this page)
printf 'banana\nApple\napple\nbanana\nCherry\n' | LC_ALL=C sort
# Apple
# Cherry
# apple
# banana
# banana

# Locale collation (GNU en_US.UTF-8)
printf 'banana\nApple\napple\nbanana\nCherry\n' | sort
# apple
# Apple
# banana
# banana
# Cherry

macOS / BSD sort

Apple ships BSD sort with the same short flags ( -f, -u, -r, -n). GNU long options such as --ignore-case / --unique are not portable. Some BSD UTF-8 collations match C byte order; set LC_ALL=C when you want that order explicitly:

LC_ALL=C sort lines.txt

printf 'banana\nApple\napple\nbanana\nCherry\n' | LC_ALL=C sort

sort -u uniques after sorting (Apple, Cherry, apple, banana). Unique on this page keeps the first occurrence without sorting (banana, Apple, apple, Cherry). sort -r reverses the comparison, not the original lines (banana, banana, apple, Cherry, Apple in C). Reverse here is Array.prototype.reverse without sorting (Cherry, banana, apple, Apple, banana). GNU tac and BSD tail -r reverse lines without sorting and match that Reverse when every line ends with LF; GNU tail has no -r, and a last line with no newline can glue onto its neighbor. sort -f folds case; on this sample in C it matches Ignore case (Apple, apple, banana, banana, Cherry). GNU sort is not stable unless -s. sort -n is numeric, so 2 before 10; this page still puts "10" before "2". uniq without sort only drops adjacent duplicates, so both bananas stay on this sample. rev reverses characters inside each line, not line order. Windows has no POSIX sort unless you use WSL or Git Bash; cmd.exe sort is a different utility. Code-unit vs locale collation is in UTF-16 vs Locale Sort: Code Units vs localeCompare.

FAQ

Does this tool upload my text?
No. Sort, Unique, Reverse, and copy run in your browser. The page does not send the text to a server.
How are lines split?
CRLF and lone CR become LF, then the string is split on LF. A single trailing empty field from a final newline is dropped so "a\nb\n" is two lines, not three. Internal blank lines stay. Lines are not trimmed.
What order does Sort use?
Array.prototype.sort with no compare function — UTF-16 code-unit order from ECMA-262. Uppercase letters sort before lowercase because A is code unit 65 and a is 97. Example: banana, Apple, apple, banana, Cherry sorted (Ignore case off) becomes Apple, Cherry, apple, banana, banana. With Ignore case, it becomes Apple, apple, banana, banana, Cherry — the sort compares toLowerCase() keys and keeps original casing. This is not localeCompare, not Intl.Collator, not Unix sort, and not a natural/numeric sort (so "10" sorts before "2"). For case conversion, see /case-converter/. For Unicode normalization, see /unicode-normalize/.
How do Unique and Reverse work?
Unique keeps the first occurrence of each key in a Set. The default key is the exact line; Ignore case uses toLowerCase(). Example: banana, Apple, apple, banana, Cherry deduped becomes banana, Apple, apple, Cherry. With Ignore case, it becomes banana, Apple, Cherry — apple is dropped because Apple already used the apple key. Reverse calls Array.prototype.reverse and does not sort. Output is lines joined with LF. No trailing newline, no column sort, and no as-you-type update.

Related