Skip to content
CornerTools

Sort Text Lines

Sort text lines alphabetically, by number, in reverse order, or randomly.

1
Sort by
Order
1
Lines: 0

Sorts lines of text A to Z, Z to A, shortest or longest first, by the number on each line, or into a random order — for lists of names, keywords, prices, scores or anything one per line.

How to use it

  • Sort by — Alphabet, Length, Number, Reverse or Random. Reverse flips the lines' current order. Random holds its order while you edit the text or change an option; Shuffle again draws a new one. Reverse and Random compare nothing, so only Remove empty lines applies to them.
  • Order — A → Z or Z → A by alphabet; shortest or longest first by length; smallest or largest first by number.
  • Decimal separator — by number only: Point by default, as in 1,234.5; Comma for 1.234,5, as most of Europe writes it. It replaces Language, which by number does not apply.
  • Language — whose alphabet decides the order: Standard by default, or Russian, Korean, Spanish, Swedish, Turkish.
  • Ignore case — off by default: sorts “apple” and “Apple” by letter alone when on.
  • Ignore whitespace — on by default: spaces at the start of a line don't move it to the top.
  • Sort numbers by value — off by default: “item 2” sorts before “item 10” when on. By length, it orders lines of equal length. Ignore case, Ignore whitespace and this switch compare text, so they do not apply by number.
  • Remove empty lines — on by default.

Whitespace and case affect only the comparison; each line keeps its original text. Lines that compare equal keep their original order.

How lines are ordered

Lines are compared by the Unicode Collation Algorithm, the same for every visitor. The Standard order puts accented letters next to their plain versions and Russian ё with е, and orders scripts Latin, then Cyrillic, then Korean Hangul in 가나다 order. A language changes this where its alphabet differs: Russian puts Cyrillic first and Korean puts Hangul first; Spanish sorts ñ after n; Swedish sorts å, ä and ö after z; Turkish treats ç, ğ, ı, ö, ş and ü as letters of their own, and with Ignore case matches I with ı and İ with i.

Numbers sort as text, digit by digit: “10” comes before “9”. Sort numbers by value compares each run of digits as a number instead.

By number, each line is sorted by the first number in it, wherever it sits: “item 10”, “10 apples” and “$10” all read as 10. A currency sign just before the digits is skipped, and a minus or plus sign just before them, or before the currency sign, is read. A hyphen after a letter or digit is not a minus, so “A-10” reads as 10 and a date such as 2026-05-01 as 2026. With the point as the decimal separator, a comma followed by exactly three digits groups thousands, so 1,234 is one thousand two hundred and thirty-four; any other comma ends the number, so “1,5” reads as 1. With the comma, the two swap roles. Lines without a number go last, in the order they were in, and lines with equal numbers keep their order in either direction. Only the digits 0 to 9 are read.

By length, each character a reader sees counts once, so an emoji or an accented letter is one character. With Ignore whitespace on, spaces at either end of a line don't count. Lines of equal length sort A to Z, in either direction.

Examples

Numbers sort as text

Text
item 9
item 10
item 2
A → Z
item 10
item 2
item 9
By value
item 2
item 9
item 10

Lines compare character by character, so “item 10” sorts before “item 2” unless numbers are sorted by value.

Prices by number

Sort by
Number
Text
Desk $1,250
Lamp $45.50
Gift card
Chair $310
Refund -$20
Smallest first
Refund -$20
Lamp $45.50
Chair $310
Desk $1,250
Gift card

The dollar signs are skipped and the comma in $1,250 groups thousands, so the desk comes last of the prices; the refund is negative, so it comes first. The gift card has no number, so it goes to the end.

Weights written with a decimal comma

Sort by
Number
Text
12,5 kg
1.200 kg
3 kg
Decimal separator: Point
1.200 kg
3 kg
12,5 kg
Decimal separator: Comma
3 kg
12,5 kg
1.200 kg

With the point, 1.200 reads as 1.2 and 12,5 as 12, since a comma before fewer than three digits ends the number. With the comma, 12,5 is twelve and a half and 1.200 is one thousand two hundred.

Mixed alphabets

Text
zebra
яблоко
사과
apple
ёж
Standard
apple
zebra
ёж
яблоко
사과
Russian
ёж
яблоко
apple
zebra
사과
Korean
사과
apple
zebra
ёж
яблоко

Each language puts its own script first and keeps the others in the standard order.

Keywords by length

Text
word counter
split pdf
qr code
merge pdf
pdf to word
Shortest first
qr code
merge pdf
split pdf
pdf to word
word counter

“split pdf” and “merge pdf” are the same length, so they sort A to Z.

See also