trimmer

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 whitespace off 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

The whitespace problem, solved once

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

Does one thing, and the edge cases too

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.

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.

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.

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.

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.

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.

Stop writing that sed one-liner.