---
title: "Sort Unique Lines action for ActionClip"
canonical_url: "https://actionclip.app/actions/sort-unique-lines"
document_type: "standalone_action"
official: true
action_count: 1
catalog_schema_version: 1
catalog_revision: "2026-08-21.1"
catalog_published_at: "2026-08-20T18:50:00Z"
---

# Sort Unique Lines action for ActionClip

Remove duplicate lines and sort the remaining text.

## What it does

Trims a list, removes exact duplicate lines, and sorts the remaining entries case-insensitively with a deterministic tie-breaker.

## Action details

| Field | Value |
| --- | --- |
| Category | Text Editing & Formatting |
| Action type | JavaScript |
| Result | Replace or copy text |
| Internet | Not required |

## Action and outcome

| Action | Outcome |
| --- | --- |
| **Sort Unique Lines** — Selected text: Mango Apple Pear Apple | Apple Mango Pear |

## How to remove duplicate lines and sort the remaining text with ActionClip

1. Select the text you want to use.
2. Choose **Sort Unique Lines** from ActionClip.
3. Review the result, then replace the selection or copy the new text.

## Requirements

No setup required.

## Privacy

Runs locally in ActionClip’s JavaScript sandbox. Selected text does not leave your Mac.

## Action configuration

````javascript
function run(selected_text) {
  const lines = selected_text
    .split(/\r\n?|\n/)
    .map((line) => line.trim())
    .filter(Boolean);

  function naturalCompare(a, b) {
    const chunksA = a.match(/\d+|\D+/g) || [];
    const chunksB = b.match(/\d+|\D+/g) || [];
    const count = Math.max(chunksA.length, chunksB.length);

    for (let index = 0; index < count; index += 1) {
      if (chunksA[index] === undefined) return -1;
      if (chunksB[index] === undefined) return 1;
      const partA = chunksA[index];
      const partB = chunksB[index];
      const numericA = /^\d+$/.test(partA);
      const numericB = /^\d+$/.test(partB);

      if (numericA && numericB) {
        const valueA = partA.replace(/^0+(?=\d)/, "");
        const valueB = partB.replace(/^0+(?=\d)/, "");
        if (valueA.length !== valueB.length) return valueA.length - valueB.length;
        if (valueA !== valueB) return valueA < valueB ? -1 : 1;
        if (partA.length !== partB.length) return partA.length - partB.length;
      } else {
        const foldedA = partA.toLocaleLowerCase();
        const foldedB = partB.toLocaleLowerCase();
        if (foldedA !== foldedB) return foldedA < foldedB ? -1 : 1;
      }
    }

    return a < b ? -1 : a > b ? 1 : 0;
  }

  return [...new Set(lines)].sort(naturalCompare).join("\n");
}
````

## Links

- [HTML listing](https://actionclip.app/actions/sort-unique-lines)
- [Download action definition](https://actionclip.app/actions/sort-unique-lines.actionclip)
- [Browse Text Editing & Formatting actions](https://actionclip.app/marketplace#marketplace-textTools)
- [All Marketplace listings](https://actionclip.app/marketplace)
