trimmer

Strip leading and trailing whitespace — stdin to stdout, single binary

A tiny Go CLI for the one job every shell script eventually needs: read stdin, write it back without the whitespace on either end. It trims the whole input by default, or every line individually with --lines — and it knows about Unicode whitespace, not just spaces and tabs.

printf ' hello world \n' | trimmer
CLI · Go · v1.0.0 · macOS · Linux · Windows

The whitespace problem, solved once.

Everyone reinvents this with sed, awk, or a subshell that eats the newline anyway. This is the small, obvious tool instead.

Synopsis

Five flags, and you will only ever use two.

trimmer [flags] # reads stdin, writes stdout-l, --lines trim each line individually -n, --no-newline do not terminate the output with a newline  --left trim leading whitespace only  --right trim trailing whitespace only  --version show version information

Clean values in scripts

-n drops the trailing newline, so the value is exactly the value.

VERSION=$(cat VERSION | trimmer -n) docker build -t app:"$VERSION" . # tidy up whatever a command hands you kubectl get pod -o name | trimmer -n

Trim every line

--lines keeps the line count — blank lines stay blank.

trimmer --lines < notes.txt > clean.txt # strip trailing whitespace from a diff-noisy file trimmer --lines --right < main.py | sponge main.py # de-indent a heredoc before feeding it onward cat <<'EOF' | trimmer --lines --left indented more EOF

Just another pipe stage

Stdin to stdout, so it drops into any pipeline you already have.

curl -s api.example.com/token | trimmer -n | pbcopy # compare two values without whitespace lying to you[ "$(cat a.txt | trimmer -n)" = "$(cat b.txt | trimmer -n)" ]# no piped input? it prints help instead of hanging trimmer

Download v1.0.0

Grab the binary for your OS — extract, drop into /usr/local/bin (or anywhere on PATH), done.

Go developer? go install github.com/wizhut/trimmer@latest — or build from source.

Small on purpose

Does one thing, and the edge cases too

The trimming is the easy part. The value is in what it gets right around it.

01

Whole input, or line by line

By default only the very start and end of the input are trimmed, so inner blank lines and indentation survive. Pass --lines and every line gets trimmed on its own, blank lines kept as blank lines.

02

Unicode-aware whitespace

Not just spaces and tabs. Carriage returns, non-breaking spaces, line and paragraph separators — anything Unicode calls whitespace comes off. CRLF input trims down to clean LF.

03

Made for command substitution

The -n flag drops the trailing newline, so VER=$(cat VERSION | trimmer -n) gives you the exact value with nothing clinging to either end. No echo, no sed, no subshell tricks.

04

One side, if you want

Use --left to strip indentation while leaving trailing spaces alone, or --right to clean line endings without touching alignment. Pass both and you are back to trimming both sides.

05

Streams, no line limit

In --lines mode input is processed as it arrives, so files larger than memory are fine and a single 10 MB line goes through intact — no 64 KiB scanner cap waiting to truncate your data.

06

Pre-built binaries, MIT licensed

Static single binaries for six targets — macOS, Linux, and Windows on both x86_64 and ARM. No Go toolchain, no runtime, no telemetry. Source on GitHub under the MIT licence.

Single static binary

Stop writing that sed one-liner

One static binary, no runtime, no config file. Put it on PATH and never think about stray whitespace again.