Line Sorter

Sort each line using alphabetical, numeric, length, or Shannon entropy complexity modes.

About this tool

This line sorter rearranges text line by line using eight sort modes: alphabetical A->Z and Z->A, numeric ascending and descending (sorted by the leading number in each line), length shortest->longest and longest->shortest, and complexity simplest->complex and complex->simple. The complexity modes use Shannon entropy - a measure of character randomness - which makes them particularly useful for security workflows like identifying high-entropy strings in log files (potential encoded payloads or tokens) or sorting password candidate lists by complexity. Additional options let you remove duplicate lines, strip empty lines, trim spaces, and show line numbers in the output.

Real example

Input (mixed log severity lines):

ERROR: connection refused
INFO: starting server
WARN: high memory usage
DEBUG: request received
ERROR: timeout exceeded

After sorting alphabetically A->Z with duplicate removal enabled:

DEBUG: request received
ERROR: connection refused
ERROR: timeout exceeded
INFO: starting server
WARN: high memory usage

For entropy-based sorting (complex->simple mode), the same lines would be reordered with the most character-diverse, random-looking strings first - useful when scanning log output for anomalous encoded values or base64 strings mixed in with normal messages.

Common use cases

  • Deduplicating dependency lists: Paste the contents of a requirements.txt, package.json dependency block, or import list, enable "Delete duplicate lines", and sort alphabetically to produce a clean, ordered list suitable for committing to version control.
  • Sorting numeric log data: Application logs often contain lines starting with timestamps, HTTP status codes, or response times. Numeric sort mode extracts the leading number from each line and sorts by that value - useful for finding the slowest response times or earliest timestamps in a batch.
  • Entropy-based anomaly detection: Base64-encoded strings, JWTs, and encrypted payloads have high Shannon entropy compared to plain-text log lines. Sort a log file by complexity descending to surface the highest-entropy lines first - these are the candidates most worth examining in a security review.
  • Keyword and tag list preparation: Sort a list of SEO keywords, tags, or content categories alphabetically with duplicate removal to produce a clean, deduplicated reference list before importing into a CMS or spreadsheet.

How it works

Sorting runs in a Web Worker to keep the UI responsive for large files. Alphabetical sort uses String.localeCompare() with optional case-sensitivity. Numeric sort extracts the leading numeric value from each line using a regex (/^[\s]*([+-]\d+(:\.\d+))/) and sorts by that number - lines without a leading number sort to the end. Length sort compares String.length. Shannon entropy is calculated per line as -∑(p_i × log₂(p_i)) where p_i is the frequency of each distinct character divided by the line length. A line of all identical characters has entropy 0; a truly random string approaches log₂(charset_size).

Common mistakes

  • Alphabetical sort ordering numbers incorrectly: In alphabetical mode, "10" sorts before "2" because "1" comes before "2" lexicographically. Use numeric sort mode when your lines start with numbers to get mathematically correct ordering.
  • Duplicate removal is case-sensitive by default: "Error" and "error" are treated as distinct lines. If you want case-insensitive deduplication, the current version does not support it directly - normalize case first with the Case Converter before pasting into the sorter.
  • Entropy mode gives unexpected results for short lines: Very short lines (1-3 characters) have artificially low entropy simply because there are fewer characters to vary. In mixed-length log files, entropy sort works best on lines of similar length or when lines are at least 8-10 characters long.

FAQ

What is Shannon entropy and why is it useful for sorting
Shannon entropy measures how unpredictable or random a string's characters are. A line containing "aaaaaaa" has entropy 0 (completely predictable). A line containing a JWT or base64 payload has entropy near 5-6 bits per character (highly varied). Sorting by entropy descending surfaces the most structurally complex lines first, which is useful for identifying encoded data, tokens, or obfuscated content in log files.

How large a file can I sort
The sorter uses a Web Worker and can handle files with tens of thousands of lines without blocking the browser UI. For extremely large files (hundreds of thousands of lines), sorting may take a few seconds. There is no strict size limit, but browser memory is the practical ceiling.

Can I remove duplicate lines
Yes. Enable "Delete duplicate lines" before sorting. Deduplication runs after preprocessing (trimming, blank line removal) and before sorting, so the final output will have all duplicates removed.

Is anything sent to a server
No. Sorting runs in a browser Web Worker - a local JavaScript thread - and no text leaves your browser.

Related tools

  • Word Counter — count lines and words in your sorted output
  • Diff Checker — compare sorted output against the original to verify changes
  • Case Converter — normalize case before sorting to avoid case-order inconsistencies
  • Regex Tester — filter lines using a regex pattern before sorting