Invisible whitespace is one of the most insidious data quality problems. Two lines that look identical may actually be different because one has a trailing space. This breaks deduplication, causes lookup failures, and corrupts imports. Here's how to fix it.

What Is Whitespace Trimming?

Trimming removes spaces, tabs, and other invisible characters from the start (leading) and end (trailing) of each line. " hello world " becomes "hello world". The content is unchanged; only the invisible padding is removed.

Trim Online (Fastest)

Open remove-lines.com, enable Trim Whitespace, paste your list, and click Process. Every line is trimmed instantly. This is especially useful before deduplication — trim first, then dedupe to catch "duplicates" that only differed by whitespace.

Trim whitespace from your list

Instant, free, private — runs entirely in your browser.

Open the tool →

Excel: TRIM Function

Excel's TRIM() function removes leading/trailing spaces and also collapses multiple internal spaces to single spaces:

=TRIM(A1)

Apply to a whole column by dragging the formula down, then paste-as-values to replace the originals.

Python: strip()

with open('input.txt') as f:
    lines = f.readlines()

trimmed = [l.strip() for l in lines]

with open('output.txt', 'w') as f:
    f.write('\n'.join(trimmed))

Use lstrip() for leading only, rstrip() for trailing only, or strip() for both.

Command Line

# Remove leading/trailing spaces with sed
sed 's/^[[:space:]]*//;s/[[:space:]]*$//' input.txt > output.txt

Tabs vs Spaces

Trimming removes both spaces and tab characters by default in most tools. If you specifically want to remove only spaces (preserve tabs), you'll need a custom regex. remove-lines.com's trim function strips both for maximum compatibility.

When to Trim

Always trim before: deduplication, database imports, email validation, alphabetical sorting, and any comparison operation. It's a safe operation with no downsides when applied to line-based data.