# Sort lines

Sort lines alphabetically, naturally (file2 before file10), by number or by length, or reverse their order.

- Endpoint: `POST https://setget.net/v1/tools/sort-lines` with JSON `{"input": {...}}`
- MCP: `run_tool` with `slug` = `sort-lines`
- Page: https://setget.net/tools/sort-lines

## Inputs

- `text` (required, string): The lines to sort.
- `order` (optional, string, one of `alphabetical`, `natural`, `numeric`, `length`, `reverse`, default `"alphabetical"`): How to order the lines. "natural" sorts numbers inside text by value; "reverse" just flips the current order.
- `descending` (optional, boolean, default `false`): Sort from last to first (Z to A, largest to smallest).
- `case_sensitive` (optional, boolean, default `false`): Treat upper and lower case as different. Capitals then sort before lower case.
- `unique` (optional, boolean, default `false`): Remove duplicate lines before sorting.

## Example 1

```json
{"input":{"text":"file10\nfile2\nfile1","order":"natural"}}
```

Result:

```json
{"text":"file1\nfile2\nfile10","lines":3,"removed":0}
```

## Example 2: Alphabetical, ignoring case, without duplicates

```json
{"input":{"text":"banana\nApple\ncherry\napple","unique":true}}
```

Result:

```json
{"text":"Apple\nbanana\ncherry","lines":3,"removed":1}
```

## Example 3: By leading number, largest first

```json
{"input":{"text":"10 apples\n9 pears\n100 plums","order":"numeric","descending":true}}
```

Result:

```json
{"text":"100 plums\n10 apples\n9 pears","lines":3,"removed":0}
```

**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.
