# Text trailing whitespace trim

`text-trailing-whitespace-trim` · version 1.0.0 · Text · free, no key needed

Remove trailing whitespace from each line in a text.

**Use when you need to: text trailing whitespace trim · trim trailing whitespace · remove trailing whitespace.**

## Supported

- text trailing whitespace trim
- trim trailing whitespace
- remove trailing whitespace

## Not supported

- trim leading whitespace
- normalize line endings
- read files

## Behavior

- Trailing whitespace (spaces and tabs) is removed from each line before the line ending (or EOF).
- Only \t and space characters are considered trailing whitespace. Form feeds, vertical tabs or other Unicode spaces are not stripped.
- Line endings (CRLF, CR, LF) are preserved.
- Returns the modified text and the number of lines that were altered.

## Input

- `text` (string, required): max length 1048576

## Output

- `text` (string, required): max length 1048576
- `trimmed_lines` (integer, required): min 0

## Limits

- max text bytes: 1048576
- max output bytes: 1048576

## Example

Request input:

```json
{
  "text": "a \n b\t\r\nc   "
}
```

Response:

```json
{
  "result": {
    "text": "a\n b\r\nc",
    "trimmed_lines": 3
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "text-trailing-whitespace-trim",
  "version": "1.0.0",
  "input": {
    "text": "a \n b\t\r\nc   "
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/text-trailing-whitespace-trim/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"text":"a \n b\t\r\nc   "}'
```

The machine-readable contract is at [/v1/tools/text-trailing-whitespace-trim/versions/1.0.0](/v1/tools/text-trailing-whitespace-trim/versions/1.0.0).

### CLI

```sh
node cli.mjs run text-trailing-whitespace-trim 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Text lines multiset subtract](/tools/text-lines-multiset-subtract): Multiset subtract b from a: remaining counts, first-seen order from a.
- [Text strip BOM](/tools/text-strip-bom): Remove one leading U+FEFF byte-order mark from a Unicode string.
- [Text apply unified patch](/tools/text-apply-unified-patch): Apply a one-file unified patch to text at original line addresses with exact hunk matches.
- [Text conflict parse](/tools/text-conflict-parse): Parse merge or diff3 conflict-marker text into ordered text and conflict parts.
- [Text conflict render](/tools/text-conflict-render): Render text and conflict parts as merge or diff3 conflict-marker text.
- [Text control characters find](/tools/text-control-characters-find): Find non-whitespace control characters in a text string.
