Skip to content
DevToolKit

Text Sort

Sort lines alphabetically, naturally, by length, word count, IP address, or column with locale-aware collation and deduplication.

Sort Settings

Distinguish A vs a
Remove leading/trailing spaces
Strip empty lines
Keep only unique lines
Sort Workbench
0 lines
Output0 lines
// Sorted result will appear here
Was this tool helpful?

How to Use

This tool sorts lines of text using nine different methods, from simple alphabetical to IP address ordering. All sorting runs locally in your browser with no server round-trip.

  1. Paste your text into the input area, one item per line. You can also click "Load Sample" for ready-made test data.
  2. Choose a sort mode from the sidebar. Alphabetical uses locale-aware dictionary order. Natural sort handles embedded numbers correctly (Item 2 before Item 10). Numeric extracts leading numbers. Line Length and Word Count sort by structural properties.
  3. Pick ascending or descending direction. This reverses the sorted result without changing the algorithm.
  4. Enable filters like Remove Blank Lines, Remove Duplicates, or Trim Whitespace to clean the data during sorting.
  5. Copy or download the sorted output. Use the Swap button to feed the result back as input for multi-pass operations.

About This Tool

Text sorting is one of the most frequent operations in data processing, yet the default sort command in most editors treats all text as plain ASCII, producing incorrect results for mixed-case text, embedded numbers, and non-English characters. This tool uses the browser's native Intl.Collator API for correct locale-sensitive ordering.

Sort Modes Explained

Alphabetical sorts using the standard Unicode Collation Algorithm, which handles accented characters and language-specific ordering rules. Natural sort enables the numeric: true option in the collator, so embedded number sequences are compared by numeric value rather than digit-by-digit. This means "file2.txt" sorts before "file10.txt" — matching how humans expect to read numbered lists.

Numeric sort extracts the leading number from each line and sorts by its parsed float value, useful for data like "42.5 kg" or "100 units". Line Length and Word Count sort by structural metrics, which is useful for finding outliers in log files or formatting text for visual alignment.

Performance

The tool pre-instantiates a single Intl.Collator object and passes its .compare method directly to Array.prototype.sort(). This avoids the overhead of creating a new collator on every comparison, which can be up to 10x faster for large arrays. For lists exceeding 100,000 lines, sort performance depends on your browser's V8/SpiderMonkey engine optimization of TimSort.

Column Sorting

The "By Column" mode splits each line using a configurable delimiter (tab, comma, semicolon, pipe, or space) and sorts by the value in a specific column. This handles simple CSV/TSV data without needing a spreadsheet. Column values are compared using natural sort, so numeric columns are handled correctly.

Why Use This Tool

Sorting text comes up in countless workflows. Here are the most common reasons developers and data professionals use this tool:

  • Data cleanup — Sort CSV rows, JSON keys, environment variables, or configuration entries alphabetically. Remove duplicates and blank lines simultaneously for a clean, canonical list.
  • Log analysis — Sort server logs by IP address, sort error messages by frequency (using the dedup + count workflow in Remove Duplicate Lines), or sort timestamped entries chronologically.
  • Dependency management — Alphabetize package.json dependencies, requirements.txt entries, or import statements. Many style guides and linters require sorted imports.
  • Natural file ordering — File names with numbers need natural sort to appear in the correct order. "chapter-2.md" should come before "chapter-10.md", not after.
  • Network administration — Sort IP address lists for firewall rules, allowlists, or audit logs. The IPv4 sort mode compares each octet numerically.
  • Content management — Sort glossary entries, bibliography items, menu options, or sitemap URLs for consistent publishing.

Privacy

All sorting happens entirely in your browser using the native JavaScript sort and Intl.Collator APIs. No text is transmitted to any server. Your data never leaves your machine, making this safe for sorting proprietary code, internal hostnames, customer lists, or any sensitive data.

FAQ

What sort orders are available?
Alphabetical (A-Z), reverse alphabetical (Z-A), numeric, by line length, and random shuffle.
Can I remove duplicate lines?
Yes. Toggle the "Remove duplicates" option to automatically eliminate duplicate lines during sorting.
Is my text sent to a server?
No. All sorting happens locally in your browser.