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

Line Sorter & Transformer

← All Tools

Input

0 lines · 0 chars

Output

0 lines · 0 chars

What is Line Sorter?

Line Sorter sorts lines of text alphabetically, numerically, by length, or randomly. It supports ascending and descending order, case-sensitive and case-insensitive sorting, deduplication (remove duplicate lines), reverse (flip order), shuffle (randomize), and trimming whitespace. Each sort operation updates the line count and displays statistics about the input and output.

Line-based text sorting is a fundamental text processing operation used constantly in development: sorting lists of URLs, organizing import statements, alphabetizing entries in a configuration file, deduplicating log lines, sorting database seed data, and organizing word lists or reference data. The Unix sort command is the standard tool, but this browser-based tool works on any device without requiring terminal access.

Natural sort vs alphabetical sort: natural sort treats numbers as numbers, not characters — so '10.txt' comes after '9.txt' (not before '2.txt' as alphabetical sort would place it). Alphabetical sort: a, b, c, ..., 1, 2, 3, ..., AA, Ab. Natural sort: a, b, c, 1, 2, 10. Version numbers sort naturally: v1.9.0 < v1.10.0 < v2.0.0 (numerically), which differs from alphabetical (v1.10.0 < v1.9.0 alphabetically).

How to Use

  1. Paste lines of text into the input field.
  2. Select the sort order: alphabetical, reverse alphabetical, by length, numeric, or random.
  3. Toggle 'Case insensitive' to sort ignoring uppercase/lowercase differences.
  4. Check 'Remove duplicates' to deduplicate the list (keeps first occurrence).
  5. Click 'Sort' and copy the result — the line count updates to reflect any removed duplicates.

Examples

Sort CSS imports alphabetically

Result: @import './button'; @import './accordion'; → @import './accordion'; @import './button';

Deduplicate log entries

Result: 1,000 log lines → Remove duplicates → 234 unique entries

Sort by length (shortest first)

Result: ['apple', 'fig', 'banana'] → ['fig', 'apple', 'banana']

Frequently Asked Questions

What is the difference between alphabetical sort and natural sort?

Alphabetical (lexicographic) sort compares character codes left to right: '10' < '2' because '1' < '2' by character code. Natural sort compares number runs numerically within strings: '2' < '10' because 2 < 10. This matters for file names with numbers: report-1.txt, report-2.txt, report-10.txt alphabetically sorts as 1, 10, 2; naturally sorts as 1, 2, 10. Always use natural sort for version numbers, file names, and any list containing numbers.

How do I sort lines in VS Code?

VS Code built-in: Edit menu → Sort Lines Ascending / Sort Lines Descending. Or: Cmd+Shift+P → 'Sort Lines Ascending'. This sorts the selected lines alphabetically. For more options (numeric, deduplicate, by length), use the 'Sort Lines' extension. For command-line sorting: sort file.txt (ascending), sort -r file.txt (descending), sort -u file.txt (unique, removes duplicates), sort -n file.txt (numeric sort).

How do I remove duplicate lines in a text file?

Browser tool: paste, toggle 'Remove duplicates'. Command line: sort -u file.txt > deduped.txt (sorts and removes duplicates). For preserving order: awk '!seen[$0]++' file.txt (keeps first occurrence of each line without sorting). Python: lines = open('file.txt').readlines(); deduped = list(dict.fromkeys(lines)); (preserves insertion order in Python 3.7+). SQL: SELECT DISTINCT text_column FROM table_name.

What is a stable sort and does it matter here?

A stable sort preserves the relative order of elements that compare as equal. For line sorting by content, duplicate lines that are 'equal' could appear in any order — stability doesn't matter if you're also deduplicating. When sorting by length, stability matters: if two lines have the same length, a stable sort keeps them in their original order. Most modern sort implementations (browsers' Array.sort(), Python's sort) are stable.

How do I sort lines in a different locale order?

Alphabetical sort depends on locale. In English, 'a' comes before 'b'. In German, 'ä' sorts between 'a' and 'b'. In Swedish, 'å' comes after 'z'. The JavaScript Intl.Collator API enables locale-aware sorting: lines.sort((a,b) => new Intl.Collator('de').compare(a,b)) for German locale. For accent-insensitive sort: Intl.Collator('en', {sensitivity:'base'}).compare() treats 'é' and 'e' as equal.

Related Tools