Skip to line trimming guide
FormatInstant
Ad spaceADVERTISEMENT
GuidesBlogFAQ
Home/Tools/Trim Each Line

FREE · CLIENT-SIDE · TEXT CLEANUP

Trim whitespace on each line

Remove leading and trailing whitespace from every line while preserving the sequence of lines, including empty lines. This can tidy copied lists, but may alter meaningful indentation.

Open Trim Each Line →

TOOL GUIDE · LINE WHITESPACE

What counts as trimming

The input is split using common CRLF, CR, and LF newline sequences. Each line is passed through JavaScript’s trim operation, which removes leading and trailing whitespace for that line. The output joins the lines with LF characters. Empty lines remain in their positions, though whitespace that previously occupied a line is removed.

This is useful for cleaning accidental spaces around copied text, but indentation can convey structure in Python, YAML, Markdown, fixed-width records, or carefully formatted code. Review the source before running the tool if whitespace might be meaningful.

Check for unintended changes

  1. Keep an original copy when the text is important.
  2. Inspect blank lines and the first/last characters of representative rows.
  3. Compare line counts if downstream processing depends on record boundaries.
  4. Run the result through the destination parser or test.

For other line utilities, see Remove Duplicate Lines and Sort Lines.

The cleanup runs locally in this browser tab. It does not modify a file on your device unless you copy the result elsewhere.

FormatInstant

Private-by-design formatting for everyday text.

All tool guidesPrivacyContact

Privacy notice: No third-party analytics or advertising cookies are active in this build. Formatting runs locally. See the Privacy Policy.