Sort Lines
Sort lines of text online alphabetically, naturally (item 2 before item 10), by number or by length, in ascending or descending order. Runs in your browser.
Something not working, or missing a feature? Send feedback
About the Sort Lines
The Sort Lines tool sorts a list alphabetically, naturally (so item 2 comes before item 10), by a leading number or by length, ascending or descending. It can also reverse the current order, drop empty lines and remove duplicates in the same step.
Everything runs in your browser, so your input is never uploaded to a server.
How to use the Sort Lines
- Paste your text, one item per line.
- Pick the sort order and the direction, and choose whether upper and lower case are sorted separately.
- Optionally remove duplicates and empty lines, then copy or download the sorted list.
Examples
Input
file10.txt file2.txt File1.txt file20.txt file3.txt
Result
File1.txt file2.txt file3.txt file10.txt file20.txt
Numbers are compared by value, and upper and lower case are sorted together.
Input
file10.txt file2.txt File1.txt file20.txt file3.txt
Result
File1.txt file10.txt file2.txt file20.txt file3.txt
Character-by-character comparison puts file10.txt before file2.txt. This is why natural sort is the default.
Input
42 Oslo 7 Paris -3 Reykjavik 100 Lima Tokyo
Result
100 Lima 42 Oslo 7 Paris -3 Reykjavik Tokyo
Lines are ordered by their leading number. Tokyo has no number, so it goes last in either direction.
Common mistakes
- Alphabetical sort for numbered items. Alphabetical order puts 10 before 2. Use natural or numeric sort for anything with numbers in it.
- Sorting lines that belong together. Sorting works line by line, so multi-line records (such as addresses) get split apart. Put each record on one line first, for example as CSV.
Works well with the Sort Lines
- Remove Duplicate Lines: remove duplicates without changing the order.
- Case Converter: normalise the case of every line first.
- Text & Code Diff: compare two sorted lists.
Frequently asked questions
What is natural sort?
Natural sort compares numbers inside text by value, so file2.txt comes before file10.txt. A plain alphabetical sort compares character by character and puts file10.txt first, because "1" sorts before "2".
How does numeric sort work?
Lines are ordered by the number they start with, including negative and decimal numbers. Lines that do not start with a number go to the end.
Is sorting the same in every language?
This tool uses English collation rules for consistent results. Accented letters sort next to their base letter, for example é next to e.
Related tools
Case Converter
Convert text between camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE, Title Case and more online. Rename variables and keys in one paste.
Remove Duplicate Lines
Remove duplicate lines from text online, keeping the first occurrence and the original order. Optionally ignore case, extra spaces and empty lines.
URL Parser
Parse a URL online into protocol, host, port, path, query parameters and fragment. Read long tracking links and debug query strings at a glance.
Cron Expression Parser
Explain any cron expression in plain English and see its next run times in your time zone. Validates crontab syntax, steps, ranges, names and @daily macros.
Word & Character Counter
Count words, characters, lines, sentences and bytes online, with estimated reading time. Check essays, posts and meta descriptions against length limits.
JSON Formatter
Format and beautify JSON with configurable indentation and optional key sorting. Errors are reported with exact line and column.