Sort lines
Sort lines alphabetically, naturally (file2 before file10), by number or by length, or reverse their order.
Input
Result
Fill in the input and press Run.
Your input is processed in memory and then discarded. It is not stored or logged. Even so, don't paste live passwords or keys into any online tool.
Use it from code or an agent
curl -s https://setget.net/v1/tools/sort-lines \
-H 'Content-Type: application/json' \
-d '{"input":{"text":"file10\nfile2\nfile1","order":"natural"}}'
import json, urllib.request
body = {'input': {'text': 'file10\nfile2\nfile1', 'order': 'natural'}}
request = urllib.request.Request("https://setget.net/v1/tools/sort-lines", json.dumps(body).encode(),
{"Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(request))["result"])
const response = await fetch("https://setget.net/v1/tools/sort-lines", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({"input":{"text":"file10\nfile2\nfile1","order":"natural"}}),
});
console.log((await response.json()).result);
Tool: run_tool
Arguments:
{
"slug": "sort-lines",
"input": {
"text": "file10\nfile2\nfile1",
"order": "natural"
}
}
{
"input": {
"text": "file10\nfile2\nfile1",
"order": "natural"
}
}
Endpoint: POST /v1/tools/sort-lines. Over MCP: run_tool with slug: "sort-lines".
Machine-readable: input schema, Markdown. Connect an agent.
Inputs
| Name | Type | Required | What it does |
|---|---|---|---|
text |
string | yes | The lines to sort. |
order |
string | no | How to order the lines. "natural" sorts numbers inside text by value; "reverse" just flips the current order. One of: alphabetical, natural, numeric, length, reverse. Default: "alphabetical". |
descending |
boolean | no | Sort from last to first (Z to A, largest to smallest). Default: false. |
case_sensitive |
boolean | no | Treat upper and lower case as different. Capitals then sort before lower case. Default: false. |
unique |
boolean | no | Remove duplicate lines before sorting. Default: false. |
Examples
Input
{
"text": "file10\nfile2\nfile1",
"order": "natural"
}Result
{
"text": "file1\nfile2\nfile10",
"lines": 3,
"removed": 0
}Alphabetical, ignoring case, without duplicates
Input
{
"text": "banana\nApple\ncherry\napple",
"unique": true
}Result
{
"text": "Apple\nbanana\ncherry",
"lines": 3,
"removed": 1
}By leading number, largest first
Input
{
"text": "10 apples\n9 pears\n100 plums",
"order": "numeric",
"descending": true
}Result
{
"text": "100 plums\n10 apples\n9 pears",
"lines": 3,
"removed": 0
}Questions
- What is natural order?
- Numbers inside the text are compared by value, so "file2" comes before "file10". Plain alphabetical order puts "file10" first.
- How does numeric order treat lines without a number?
- Lines are ordered by the number they start with. Lines that do not start with a number go last, in their original order.
- Is the result always the same?
- Yes. Lines that compare as equal keep the order they had in the input.
Related tools
- Remove duplicate linesRemove repeated lines from text, keeping the first occurrence of each and the original order.
dedupe-lines - Reverse textReverse text by characters, by words or by lines. Accents and emoji stay attached to their letters.
reverse-text - CSV sort, filter and dedupeSort CSV by a column, keep rows containing some text, pick columns and remove duplicate rows.
csv-sort-filter-dedupe - Apply a patchApply a unified diff to a text and get the patched result, with clear errors when a hunk does not fit.
patch-apply - Case converterConvert text between lower, UPPER, Title, Sentence, camelCase, PascalCase, snake_case, kebab-case and more.
case-convert - Escape and unescape textEscape or unescape text for HTML, URLs, JSON strings, shell commands, regular expressions and CSV fields.
escape-unescape