Skip to main content
SerpGem
Content Tool

Sort Lines

Sort any list of lines 8 ways — A→Z, Z→A, numerical, by length, reverse, or random shuffle. Optional deduplication, whitespace trim, and empty-line removal all in one pass.

InputLines to sort

Sort mode

OutputSorted output
(empty)

Use this with

See all 10 tools

Line Sorting Guide

Eight ways to order any list

Sorting is a small task you do constantly in SEO work — cleaning keyword exports, ordering URLs, prioritizing internal link anchors. This tool gives you eight sort modes in a single paste, with all the cleanup options you need in one pass.

Alphabetical A→Z and Z→A

The default for keyword lists, email lists, domain lists, or anything where you want consistent lookup order. Case-insensitive by default; toggle if case matters for your use case.

Numerical sort

Extracts the first number in each line and sorts by that — useful for lines like "Page 1 — Home", "Page 10 — Pricing". Plain alphabetical sorting puts "10" before "2"; numerical sort does it correctly.

Sort by length

Short → long or long → short. Useful for spotting outliers — e.g., finding suspiciously long keywords in a list, or finding the shortest URL variants to canonicalize toward.

Reverse

Flips whatever order the lines are already in — useful for time-ordered exports where you want newest first instead of oldest first.

Shuffle

Random order via Fisher-Yates. Good for A/B test variant ordering, randomized content rotation lists, or any time you want to kill ordering bias.

Combine with cleanup

All options apply in a single pass: sort + dedupe + trim + empty-line removal. No need to run three tools in sequence — paste once, check the boxes, copy the result.

Pro Tips

Numerical sort gotcha

Numerical mode reads the FIRST number in each line. 'Chapter 2 — Year 2024' sorts by 2, not 2024. If that's wrong for your data, consider numbering lines consistently first.

Unique + sort combo

Checking 'unique only' plus any alphabetical sort gives you the classic shell `sort | uniq` result — clean, deduplicated, ordered. Essential for merging keyword lists.

Keep original casing

Turn ON "case sensitive" if you want ABC before abc. Leave it OFF (default) for natural-looking alphabetical order where case is ignored for comparison.

?

Frequently Asked Questions

Does sorting preserve blank lines?
Only if you turn OFF 'remove empty lines'. When on (default), blanks are stripped before sorting — usually what you want for clean output.
How does numerical sort work with non-numeric lines?
Lines with no numbers are treated as infinity, so they sort last (or first when descending). Useful for surfacing "uncategorized" entries at one end.
Can I sort by a specific column or field?
Not directly — this is a line sorter, not a CSV sorter. If you have CSV data, extract the column you want to sort by, or consider splitting the file into separate columns first with our Find & Replace tool.
Is shuffle truly random?
It uses Math.random() via Fisher-Yates, which is a solid uniform shuffle but not cryptographically secure. For high-stakes randomness (e.g., lotteries), don't use this tool.