filemarkr
All ToolsGuides
filemarkr

60+ free developer tools that run entirely in your browser — JSON formatter, JWT decoder, Base64, diff checker, regex tester, hash generator and more. No upload, no sign-up, completely private.

JSON & Data

  • JSON Formatter
  • JSON Minifier
  • JSON Validator
  • JSON to CSV
  • CSV to JSON
  • JSON to YAML

Encode & Decode

  • Base64 Encode / Decode
  • Base64 to Image
  • Image to Base64
  • URL Encode / Decode
  • HTML Entity Encoder
  • JWT Decoder

Text Tools

  • Text Diff Checker
  • Case Converter
  • Word & Character Counter
  • Slug Generator
  • Remove Duplicate Lines
  • Sort Text Lines

Generators

  • UUID Generator
  • Password Generator
  • Lorem Ipsum Generator
  • QR Code Generator
  • Random Number Generator
  • NanoID Generator

Popular Guides

  • How to Format and Pretty-Print JSON (Without Breaking It)
  • How to Minify JSON and Shrink Your API Payloads
  • How to Validate JSON and Pinpoint the Exact Syntax Error
  • How to Convert JSON to CSV for Excel and Google Sheets
  • How to Convert CSV to JSON (With Proper Header Detection)
  • All guides →

Explore

  • All Tools
  • JSON Formatter
  • JWT Decoder
  • Diff Checker
  • UUID Generator

Company

  • About
  • Privacy
  • Terms
  • Sitemap

Our Promise

  • 100% in your browser
  • Zero uploads
  • No sign-up, always free

© 2026 filemarkr. Designed & developed by Naved Naik.  All processing happens locally in your browser.

All guides

Text Tools

How to Sort Lines of Text Alphabetically or Numerically

Sort lines of text alphabetically, numerically or in reverse, with case and locale options, and avoid the classic lexicographic sorting mistakes.

Try the toolSort Text Lines →

The problem: sorting is not as obvious as it looks

Alphabetizing a list, ordering version numbers, arranging log lines by timestamp: sorting text is a daily task, and the "obvious" default almost always gets numbers wrong. If you have ever seen 1, 10, 2, 3 come out of a sort, you have met the classic lexicographic trap.

How text sorting works

By default, most languages compare strings character by character using their code-point values. That means Z (code 90) sorts before a (code 97), and 10 sorts before 2 because 1 comes before 2. Watch:

['banana', 'Apple', 'cherry'].sort();
// ["Apple", "banana", "cherry"]  — uppercase wins

['10', '2', '1'].sort();
// ["1", "10", "2"]  — lexicographic, not numeric

To sort the way humans expect, you pass a comparator. For numbers, subtract:

['10', '2', '1'].sort((a, b) => a - b);
// ["1", "2", "10"]

For case-insensitive, locale-aware alphabetical order, use localeCompare:

['banana', 'Apple', 'cherry'].sort((a, b) =>
  a.localeCompare(b, undefined, { sensitivity: 'base' })
);
// ["Apple", "banana", "cherry"] — 'a' and 'A' now rank equally

And for natural sort, where file2 comes before file10, turn on the numeric option:

['file10', 'file2', 'file1'].sort((a, b) =>
  a.localeCompare(b, undefined, { numeric: true })
);
// ["file1", "file2", "file10"]

A practical walkthrough

Say you have a list of 200 country names to alphabetize for a dropdown, and a few start with accented letters like Åland and Côte d'Ivoire. A naive sort pushes the accented entries to the bottom. Paste the list into the Sort Text Lines tool, choose alphabetical and case-insensitive, and locale-aware comparison puts them where a reader expects. Flip to reverse order and you have Z to A without editing anything by hand.

Common pitfalls

  • Numbers as strings. The single most common mistake. 100 sorts before 99 lexicographically. Use numeric comparison for anything that is really a number.
  • Mixed content. Version strings like 1.9.0 and 1.10.0 need per-segment numeric comparison; plain sorting puts 1.10.0 first. Natural sort handles most of these.
  • Case surprises. A case-sensitive sort groups all uppercase before all lowercase, which looks broken to non-programmers. Case-insensitive is usually what people want for display.
  • Locale differences. In Swedish, ä sorts after z; in German it sorts near a. There is no single "correct" order; it depends on the language.
  • Stability. Equal lines should keep their relative order. Modern JavaScript sort is stable, but older comparison hacks may not be.

Related tools

Sorting and deduping go hand in hand: the Remove Duplicate Lines tool strips repeats before or after you sort. If your lines are wrapped across multiple physical lines, Remove Line Breaks can flatten them first so each item is a single sortable line.

Conclusion

The gap between a naive sort and a correct one is almost always about numbers and case. Once you know to reach for numeric comparison and locale-aware, case-insensitive ordering, sorting stops surprising you. The Sort Text Lines tool offers alphabetical, numeric and reverse ordering with case options, all running privately in your browser.

More guides

How to Format and Pretty-Print JSON (Without Breaking It)

Read

How to Minify JSON and Shrink Your API Payloads

Read

How to Validate JSON and Pinpoint the Exact Syntax Error

Read

How to Convert JSON to CSV for Excel and Google Sheets

Read