Skip to main content
Text Tools

Sort Lines

Alphabetize lists, sort lines A–Z, Z–A, by string length, numerically, or in reverse order.

What is the Sort Lines?

The Sort Lines tool alphabetizes and organizes multi-line text lists according to diverse sorting criteria: Alphabetical (A to Z), Reverse Alphabetical (Z to A), Natural Numeric order (properly ordering 1, 2, 10 instead of 1, 10, 2), Length (shortest to longest), and randomized shuffle. It cleans up unorganized lists with zero effort.

Organizing lists alphabetically or numerically is essential for dictionary glossaries, index compilations, coding import statements, CSV row ordering, customer contact lists, and inventory management catalogs.

How to Use the Sort Lines

  1. Paste Your List: Insert your unorganized list into the input box.
  2. Select Sorting Criterion: Click A → Z, Z → A, Numeric Sort, or Sort by Length.
  3. Optional Deduplication: Check 'Remove duplicate lines' to simultaneously deduplicate while sorting.
  4. Copy Sorted List: Copy your structured list ready for immediate use.

Formula & How It Works

Sorting applies JavaScript's localeCompare with natural numeric collation:

1. Alphabetical (A-Z):
   lines.sort((a, b) => a.localeCompare(b, undefined, { sensitivity: 'base' }))

2. Reverse (Z-A):
   lines.sort((a, b) => b.localeCompare(a, undefined, { sensitivity: 'base' }))

3. Natural Numeric Sort:
   lines.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }))

4. Sort by Length:
   lines.sort((a, b) => a.length - b.length)

Worked Example: An unorganized list containing ['Item 10', 'Item 2', 'Item 1'] under natural sorting correctly orders as: 1. Item 1, 2. Item 2, 3. Item 10.

Practical Worked Examples

Sorting ModeUnsorted InputSorted Output
A to ZBanana
Apple
Cherry
Apple
Banana
Cherry
Natural NumericPage 10
Page 2
Page 1
Page 1
Page 2
Page 10
By LengthElephant
Cat
Giraffe
Cat
Giraffe
Elephant

Common Everyday & Professional Use Cases

Alphabetizing bibliographic references, sorting programming imports, organizing inventory product SKUs, ordering customer name lists, and arranging test data.

Frequently Asked Questions about Sort Lines

Standard ASCII sorting sorts character-by-character, placing '10' before '2'. Natural sorting recognizes multi-digit numbers within strings and sorts them in proper numerical order (1, 2, 10).
You can toggle the 'Trim whitespace before sorting' option to prevent leading spaces from distorting alphabetical ordering.
Yes, you can toggle case-sensitive sorting to prioritize uppercase letters before lowercase letters.
The shuffle option applies the Fisher-Yates randomization algorithm to produce an unbiased random distribution of your rows.
Lists containing up to 25,000 lines sort in well under 100 milliseconds.
Explore More

Related Free Online Tools

All Text Tools →

Word & Character Counter

Count words, characters with/without spaces, sentences, paragraphs, and estimated reading time in real time.

Case Converter

Transform text instantly between UPPERCASE, lowercase, Title Case, Sentence case, and alternating case.

Remove Duplicate Lines

Deduplicate text lists, delete redundant entries, and clean up datasets with case sensitivity options.

Remove Extra Spaces

Eliminate redundant spaces, strip trailing whitespace, normalize tabs, and fix spacing formatting errors.

Helpful Guides & Mathematical Tutorials