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' | trimmerEveryone reinvents this with sed, awk, or a subshell that eats the newline anyway. This is the small, obvious tool instead.
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
-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
--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
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
Grab the binary for your OS — extract, drop into /usr/local/bin (or anywhere on PATH), done.
arm64
x86_64
x86_64
arm64
x86_64
arm64
Go developer? go install github.com/wizhut/trimmer@latest — or build from source.
Small on purpose
The trimming is the easy part. The value is in what it gets right around it.
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.
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.
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.
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.
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.
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
One static binary, no runtime, no config file. Put it on PATH and never think about stray whitespace again.