PureDevTools

Sort Text Lines

Sort lines alphabetically, numerically, or naturally — with reverse, case control, and blank line removal

All processing happens in your browser. No data is sent to any server.

Sort Direction

Options

Input — 0 lines

Output — 0 lines

Sorted output will appear here…

You have a list of 200 domain names, product codes, or dependency names that need to be in alphabetical order before you can compare them against another list. You could paste them into Excel, use a formula, sort the column, and copy back — or you could paste here, click “A → Z”, and be done in three seconds.

What This Tool Does

Sort Text Lines takes any block of text — one item per line — and reorders the lines according to your chosen sort criteria. It supports alphabetical (lexicographic) sorting, numeric sorting for lists of numbers, and natural sort for file names and version strings where “file10” should come after “file9” rather than between “file1” and “file2”.

Alphabetical Sort (Lexicographic)

The default sort mode is lexicographic: lines are compared character by character, using each character’s Unicode code point value. This is the standard “dictionary order” for most Western text.

With case-insensitive mode (the default):

banana
Apple
cherry

Sorts to:

Apple
banana
cherry

With case-sensitive mode on, uppercase letters sort before lowercase (because uppercase letters have lower Unicode code points than lowercase letters in ASCII):

Apple
banana
cherry

Sorts to:

Apple
banana
cherry

Case sensitivity matters when your data mixes uppercase and lowercase in meaningful ways — for example, a list of environment variable names (DATABASE_URL, api_key, PORT) where casing indicates something about the variable’s type or scope.

Numeric Sort

Lexicographic sort handles numbers incorrectly for most practical purposes:

10
2
1
20
3

Lexicographic order: 1, 10, 2, 20, 3 (because 1 < 2 < 3 in character-by-character comparison).

Numeric sort treats each line as a number and compares by numeric value:

1
2
3
10
20

Use numeric sort for lists of counts, prices, port numbers, line numbers, or any other purely numeric data.

Lines that cannot be parsed as numbers are sorted lexicographically among themselves and placed after numeric lines (or before, depending on implementation). This handles mixed lists gracefully.

Natural Sort

Natural sort (also called “human sort” or “version sort”) is designed for strings that contain embedded numbers, such as file names, version numbers, and software release names.

Compare sorting file1.txt, file2.txt, …, file10.txt:

Natural sort is the right choice for:

Descending and Reverse

Descending (Z → A) is the logical reverse of ascending sort — the same comparison algorithm runs in the opposite direction. The highest values appear first.

Reverse (available as a separate toggle) simply reverses the order of the output without re-sorting. If you sort ascending first and then reverse, you get descending order. But if your input is already sorted and you just want to flip it — or if you want to reverse an unsorted list to read it bottom-to-top — use the reverse toggle without changing direction.

These two options combine: sorting descending then reversing produces ascending order again. This is mostly useful if you want to sort by one criterion and then flip the result for a specific workflow.

Remove Blank Lines

Blank lines within a list are often noise — an accidental extra newline between items. The Remove blank lines option filters out any line that consists entirely of whitespace before sorting, giving you a clean output with no gaps.

This is different from deduplication: it only removes completely blank lines, not duplicate non-empty lines. To remove duplicate lines, use the Remove Duplicate Lines tool.

Common Use Cases

Alphabetizing Configuration Keys

nginx.conf, httpd.conf, settings.py, and similar files often have options added over time in no particular order. Sorting the keys alphabetically makes the file easier to read and review in diffs.

Sorting Import Statements

Many style guides (and linters like isort for Python or eslint-plugin-import for JavaScript) require import statements to be alphabetically sorted. Paste the imports, sort, and paste back.

Comparing Two Lists

Before you can compare two lists to find what’s in one but not the other, both lists need to be in the same order. Sort both, paste into a text diff tool, and the differences become immediately visible.

Version History and Changelog Review

A list of version tags from a git repository (v1.0.0, v1.10.0, v1.9.0) is meaningless unless sorted with natural sort. Paste the tags, enable natural sort, and read them in actual release order.

Leaderboard and Score Ranking

A list of scores or counts sorts correctly with numeric sort — 100, 95, 87, 72 in descending order, not 100, 95, 87, 72 reordered by string value.

Preparing Data for Import

Many database tools and spreadsheet importers expect sorted data for efficient lookups. Sorting before import can significantly reduce index fragmentation in some database engines.

Natural Sort vs. Lexicographic: Which to Use?

Data typeRecommended sort
Plain words, namesLexicographic
File names with numbersNatural sort
Version numbersNatural sort
Purely numeric valuesNumeric sort
IP addressesNumeric sort (per-octet is complex; for simple comparison, numeric works for most cases)
Mixed alphanumeric codesNatural sort

When in doubt, natural sort produces more human-intuitive results for most real-world data.

Privacy

All processing happens entirely in your browser. Your text is never sent to any server. The tool works offline once the page has loaded.

Frequently Asked Questions

Does this handle Unicode characters correctly? Yes. The tool uses JavaScript’s localeCompare for lexicographic and natural sorts, which handles Unicode characters correctly for most Western European languages.

What is the difference between numeric sort and natural sort? Numeric sort treats each entire line as a number. Natural sort handles numbers embedded within strings — useful for file names like report_v2_final.pdf. If your lines are purely numbers, use numeric sort. If they’re strings with numbers inside, use natural sort.

Does sorting modify the content of lines? No. Lines are reordered but their content is never changed.

Is there a line limit? No hard limit. The tool runs in your browser and handles hundreds of thousands of lines efficiently on modern hardware.

What happens to blank lines? By default, blank lines are preserved and sort to the top (they compare as empty strings, which sort before any other characters). Enable “Remove blank lines” to exclude them from the output.

Related Tools

More Text & String Tools