Sort lines
Sort text lines by dictionary order, numeric order or length
Put one item on each line and choose a rule for live sorting. Numeric mode needs a valid number on every line; reversal only flips the current order.
Example
Input
10 2 1
Example result
1 2 10
Choose numeric ascending. Lexical ascending would give 1, 10, 2.
Technical details & limits
Lexical ordering uses JavaScript string comparison, not pinyin or natural-number collation. Numeric mode requires complete finite numbers on nonempty lines so abc or 12px are not silently treated as 0 or 12. Length sorting counts UTF-16 units. Duplicate lines are retained.
About this tool
Sort lines lexically, numerically or by length in either direction, or reverse their order. Options cover case sensitivity, trimming and empty-line removal for lists and configuration data.
Use cases
- Sort a list of keys or fields.
- Sort logs by their leading timestamp.
How to use
- Paste the text to sort.
- Pick sort mode and options. The result updates live.
Notes
Numeric sorting needs the whole line to parse as a number; lines carrying units or other characters cannot take part, so use text sorting for those. Sorting happens in the browser and leaves the input untouched.
FAQ
- Why does numeric line sorting differ from alphabetical sorting?
- Numeric sorting compares numeric values, while lexical sorting compares strings. For example, 2 appears before 10 numerically, but 10 appears before 2 lexically. Numeric mode requires each nonempty line to contain a complete finite number. Mixed text such as 12px is not accepted as a partial number. Select the comparison mode before interpreting the result, especially when a list contains identifiers that only happen to contain digits.
- Does sorting text lines automatically remove duplicates?
- Sorting text lines changes their order without removing duplicate entries. If the input has 3 lines and 2 are identical, the sorted output still has 3 lines. Use the duplicate-line remover afterward when you need unique entries. Decide whether whitespace and letter case should affect equality before combining the operations, because a sorting rule and a duplicate comparison rule can otherwise produce a list that looks unexpectedly repetitive.
- Why can length sorting count a character as two positions?
- Length sorting uses UTF-16 code units, so a supplementary character contributes 2 units while an ASCII character contributes 1. Visible symbols, Unicode code points, and code units are different measurements. The resulting order therefore need not match an order based on how many symbols a reader sees. Do not use these lengths to estimate UTF-8 file sizes, which require counting the encoded bytes instead of JavaScript string units.
Related tools