Sorting and deduping lines
Published: 2026-09-05
How to reorder multi-line lists and remove duplicates—locale sort, numeric digit order, case folding, keep-first vs sort-unique, reverse, and shuffle—without uploading the paste.
Pastes of emails, IDs, tags, log hosts, or spreadsheet columns often arrive as one value per line. Two jobs come up constantly: put those lines in a stable order, and drop repeats. Spreadsheet sorts and shell pipelines (sort, uniq) work, but for a quick browser pass—especially when the list is sensitive—local tools keep the text in the tab.
LocalTools ships Sort lines and Dedupe lines. Both split on JavaScript newline rules (LF, CR, or CRLF), preserve a trailing newline when present, and never upload the paste.
Sort vs dedupe (and when to chain them)
| Goal | Prefer | Notes |
|---|---|---|
| Alphabetical or reverse order | Sort lines | Ascending / descending with locale rules |
| Flip current order only | Sort → Reverse | Does not re-alphabetize |
| Randomize for sampling | Sort → Shuffle | New permutation each shuffle |
| Drop repeats, keep encounter order | Dedupe → Keep first occurrence | First spelling wins |
| Unique set, then A→Z | Dedupe → Sort unique | Dedupe then locale sort |
Typical cleanup: dedupe first (or use sort-unique), then sort if you still need a different order. Sorting alone does not remove duplicates—adjacent equals stay unless you dedupe.
What “sorted” means: locale, case, and digits
Browsers order strings with Unicode collation for the current locale, not a simple ASCII byte chart. That affects accents (é vs e) and language-specific letter order.
For A→Z / Z→A (and for dedupe’s sorted mode), LocalTools exposes:
- Case-insensitive (accent-aware) — usual default for human lists;
Appleandapplegroup together when sorting, and count as the same line when deduping (the first spelling is kept). - Case-sensitive — exact comparison; useful when
Prodandprodmust stay distinct. - Lexicographic vs numeric digits — lexicographic puts
10before2("1"<"2"). Numeric digit ordering puts2before10, which matches how people expect version fragments and numbered labels to read.
Reverse and shuffle ignore comparison options: reverse flips the current sequence; shuffle uses Web Crypto randomness per action (use Shuffle again for another permutation).
Dedupe details that surprise people
- Empty lines count like any other line—two blank rows are duplicates of each other.
- Leading/trailing spaces are part of the line.
"alpha "and"alpha"are different unless you normalize first with Whitespace normalizer. - Case-insensitive match folds for comparison only; output keeps the first representative’s casing and accents.
- “Repeated occurrences removed” counts extras after the first keep—not how many distinct keys you had.
If you need fuzzy near-duplicates (typos), line equality is the wrong tool; see Levenshtein distance later, or edit with Find & replace (batch).
Practical workflow
- Paste one item per line (exports from sheets,
grepoutput, CMS tag lists). - If whitespace is noisy, normalize CRLF/tabs/trailing spaces first.
- Dedupe: keep first occurrence for “stable list order,” or sort unique for a clean glossary.
- Sort when you need A→Z, Z→A, reverse, or a random sample order.
- Copy the output; check line counts under the boxes when you care how many rows dropped.
For measuring length after cleanup, use Text statistics. For turning cleaned titles into URL paths, see slug rules.
Why sort and dedupe locally
Customer emails, internal hostnames, and unreleased feature flags should not ride through a remote “list cleaner.” Both tools reorder and filter entirely in the browser—same local-only model as the rest of LocalTools.
Try it locally
Sort: open Sort lines, paste, choose A→Z / Z→A / reverse / shuffle, set case and digit options for sort modes, then copy.
Dedupe: open Dedupe lines, paste, choose keep-first or sort-unique, set match sensitivity (and digit order when sorting), then copy.
Related reading
- Sort lines — locale sort, reverse, and crypto shuffle
- Dedupe lines — unique lines, keep-first or sort-unique
- Text stats: words, reading time, and limits
- Slug rules for URLs and filenames
- Text case styles: camelCase, snake_case, kebab-case
- Why “local only” matters for developer tools