Try the Sort Lines

Sort Lines β€” Sort Any List Alphabetically, Numerically, or by Length

Learn how to sort any text list alphabetically, numerically, by length, or randomly, why numerical sort differs from alphabetical for numbers, and how to use a free sort lines tool for any list.

By sadiqbd Β· June 6, 2026

Sort Lines β€” Sort Any List Alphabetically, Numerically, or by Length

Sorting a list by hand is fine for ten items and unbearable for a thousand

Alphabetically organising names for a directory. Numerically ordering a list of prices. Reversing a playlist. Sorting a keyword list to spot duplicates more easily before deduplication. Arranging code constants in a consistent order. These tasks come up constantly when working with text data, and manually dragging items around or typing them in order is exactly the kind of work a computer should do in milliseconds.

A line sorter takes any block of text β€” one item per line β€” and sorts it in whatever order you need.


Sorting Options Explained

Alphabetical (A β†’ Z)

The most common sort. Lines sorted from A to Z by their first character, then second character for ties, and so on.

Case handling matters: in strict ASCII order, uppercase letters come before lowercase (Z before a). Natural case-insensitive sorting (Apple and apple sorted equally) is more useful for most purposes and is typically the default.

Reverse alphabetical (Z β†’ A)

The same comparison, reversed. Useful when you want the highest-alphabet items first β€” or for reverse sorting after alphabetical doesn't tell you what you need.

Numerical (ascending)

For lists containing numbers, pure alphabetical sort produces wrong results:

  • Alphabetical: 1, 10, 100, 2, 20, 3
  • Numerical ascending: 1, 2, 3, 10, 20, 100

Numerical sort treats the value of the number, not the character sequence.

Numerical (descending)

Highest to lowest: 100, 20, 10, 3, 2, 1

By length (shortest to longest)

Sorts lines by character count. cat before elephant.

By length (longest to shortest)

Reversed β€” elephant before cat.

Reverse / flip order

Reverses the current order without sorting β€” last line becomes first, first becomes last.

Random shuffle

Randomises the order of lines. Useful for creating random samples, shuffling playlists, or randomising quiz questions.


How to Use the Sort Lines Tool on sadiqbd.com

  1. Paste your list β€” one item per line
  2. Choose sort type β€” alphabetical, numerical, by length, reverse, or random
  3. Configure options β€” case sensitivity, remove blanks
  4. Sort β€” the result appears instantly
  5. Copy β€” sorted list ready to use

Real-World Examples

Alphabetising a contact list

A list of 500 contact names needs to be alphabetically ordered for a directory:

Before: Rahman, Sadiqur, Akter, Farida, Hossain, Kamal, ... After: Akter, Farida, Hossain, Kamal, Rahman, Sadiqur, ...

Alphabetical sort by surname (in Lastname, Firstname format) produces the directory order.

Ordering CSS classes in HTML

A coding style guide requires CSS class names in HTML elements to be alphabetically ordered:

Before: class="rounded-lg text-white bg-blue-500 font-bold p-4" After: class="bg-blue-500 font-bold p-4 rounded-lg text-white"

The class names sorted alphabetically are easier to scan and confirm against the style guide.

Numerical sort for prices

A product list with prices:

Alphabetical (wrong): 100, 1000, 200, 25, 50 Numerical ascending (correct): 25, 50, 100, 200, 1000

Alphabetical sort treats these as strings and sorts character by character, not by value. Numerical sort treats them correctly.

Pre-deduplication sort

Sorting a keyword list alphabetically before deduplication makes duplicates adjacent and easier to spot manually. Even if using an automated deduplication tool, alphabetical sorting first is a useful sanity check.

Random sampling

A list of 200 test user IDs needs to be shuffled so the first 20 can be selected as a random sample for a usability test. Shuffle the list, take the first 20 β€” properly random without any bias in selection.

Code constant ordering

A configuration file has constants that should be alphabetically organised:

# Before
MAX_UPLOAD_SIZE = 10485760
API_KEY_LENGTH = 32
CACHE_TTL = 3600
BASE_URL = "https://api.example.com"

# After (sorted alphabetically by constant name)
API_KEY_LENGTH = 32
BASE_URL = "https://api.example.com"
CACHE_TTL = 3600
MAX_UPLOAD_SIZE = 10485760

Alphabetical ordering makes configuration files easier to scan and reduces merge conflicts when multiple developers add constants.


Natural Sort vs. Lexicographic Sort

A subtlety worth understanding:

Lexicographic (string) sort β€” compares characters position by position: file1.txt, file10.txt, file2.txt, file20.txt

Natural sort β€” handles embedded numbers as numbers: file1.txt, file2.txt, file10.txt, file20.txt

For file names, version numbers, and any list where numbers are embedded in text, natural sort produces the expected order. Lexicographic sort produces technically correct string comparison but often wrong-feeling results for human-readable identifiers.


Combining Sort with Other Text Tools

Line sorting becomes even more powerful in combination with other text operations:

Sort + Deduplicate: Sort alphabetically, then remove duplicates. Duplicates become adjacent after sorting, making the deduplication more predictable.

Sort + Find and Replace: Normalise text (fix case, remove prefixes) before sorting so that similar items sort together.

Sort + Filter: Sort a list, then manually review to remove items that don't belong β€” the sorted order makes pattern-based removal easier.


Tips for Line Sorting

Use case-insensitive sort for natural text. Apple, banana, and CHERRY should sort as apple, banana, cherry β€” not CHERRY, Apple, banana. Most tools default to case-insensitive for natural language lists.

Use numerical sort whenever your list contains numbers. Alphabetical sort of numbers produces the wrong order and can cause real problems if you're ordering by price, ID, or version number.

For CSV data, sort in a spreadsheet. The sort lines tool works on whole lines. Sorting by a specific column in a CSV requires spreadsheet tools or scripting.

Random shuffle is genuinely random. If you need unbiased random ordering for sampling or test randomisation, the shuffle produces a true random permutation.


Frequently Asked Questions

Can I sort by multiple criteria? The text tool sorts by a single criterion. For multi-key sorting (e.g. sort by department, then by last name within department), use spreadsheet sorting or command-line sort with multiple -k flags.

Does sorting preserve blank lines? Most tools treat blank lines as empty strings β€” they sort before alphabetic characters in ascending order. An option to remove blank lines before sorting is useful for cleaner output.

What's the Unix equivalent? The Unix sort command handles most of these cases: sort -f for case-insensitive, sort -n for numerical, sort -r for reverse, sort -R for random. The text tool provides the same functionality without a terminal.

Can I sort lines containing non-Latin characters? Yes β€” Unicode-aware sorting handles Latin-script languages, and many tools handle other scripts with locale-aware comparison. The specific behaviour for mixed-script text varies by tool.

Is the sort lines tool free? Yes β€” completely free, no sign-up needed.


Sorting is one of the most fundamental data operations, and having a quick browser-based tool for it eliminates the need to open a spreadsheet or terminal for what should be a 5-second task.

Try the Sort Lines tool free at sadiqbd.com β€” sort any list alphabetically, numerically, by length, or randomly in one click.

Try the related tool:
Open Sort Lines

More Sort Lines articles