Text FIELD NOTES · 4 MIN READ
The Text Cleanup Pipeline: Duplicates, Whitespace, and Messy Pasted Text
Cleaning pasted text in the order that works: trim lines and whitespace, drop empties, then remove duplicates — with the case and padding options that match the job.
Text that arrives by copy-paste is almost never clean. It carries trailing spaces you cannot see, tabs masquerading as indents, blank lines from a PDF's margins, and the same entry pasted twice with slightly different padding. None of that shows up when you eyeball the text, and all of it breaks scripts, comparisons, and imports. Cleanup is a pipeline, and the order of the steps matters as much as the steps.
Whitespace: invisible until it isn't
Whitespace is not one character but several — space, tab, carriage return, line feed — and most of them render as nothing. The classic failure is a trailing space on a line: two lines that look identical are different strings, a lookup misses, a comparison reports a change. A trim-and-normalize pass fixes the whole class of problem at once:
input: " hello world " (17 characters)
normalized: "hello world" (11 characters)
The Trim Whitespace tool offers three strengths, and picking the right one is the whole game. Normalize collapses every run of internal whitespace to a single space and trims the ends — right for prose. Trim removes only the leading and trailing whitespace and leaves the interior untouched — right for lines whose internal spacing is meaningful. Remove deletes every whitespace character outright — right for keys, codes, and identifiers where a stray space is always an error.
Cleaning line by line
Multi-line text needs a per-line pass, because the mess concentrates at line edges: leading indents from copy-pasting code, trailing tabs, blank lines separating blocks. A line trimmer handles all three in one step:
input: " a \n\n b\tc \n"
collapse: each line trimmed, runs of spaces/tabs -> one space
result: "a\nb c"
4 input lines -> 2 output lines, 2 empty lines dropped
The String Trim Lines tool trims every line, drops empty lines by default, and — with the collapse option — squeezes runs of internal spaces and tabs down to one space while leaving the line breaks intact. It also understands \r\n and old Mac-style \r line endings, which matters more than it sounds: text pasted from a Windows editor often carries carriage returns that make every line look "dirty" in a comparison even when no visible character is wrong.
Duplicates: deciding what counts as "the same line"
Removing duplicate lines sounds trivial and then immediately meets philosophy: is apple the same line as Apple? Is apple (padded) the same as apple? The honest answer is "it depends on the job", which is why the Remove Duplicate Lines tool exposes the decision as options rather than hiding it:
input: apple\n apple\nApple\nbanana
caseSensitive=true: " apple" and "Apple" both survive
trim + ignore case: only "apple" and "banana" survive
5 lines -> 2 unique, 3 removed
By default the comparison is case-sensitive and whitespace-aware — Apple, apple, and apple are three different lines. Turn on whitespace trimming and case-insensitivity when you want a dedupe that matches what a human means by "the same entry". Empty lines get dropped along the way unless you ask to keep them, and the tool reports the arithmetic — original count, unique count, removed count — so you can tell a careful cleanup from a data-destroying one.
Order of operations matters
Run the steps in the wrong order and the pipeline silently misses things. Deduplicate first and apple plus apple count as two entries, because the duplicate detector compares the untrimmed strings. Trim first and the padding disappears before the comparison happens, so the duplicate is caught. The same logic applies to case: dedupe before case-folding and Apple survives next to apple. The reliable order for pasted lists is:
1. trim each line (and collapse internal runs if spacing is noise)
2. drop empty lines
3. remove duplicates (with the case/whitespace options you actually mean)
4. only now: sort, join, or count
Once the text is clean, every downstream tool behaves better. A frequency count stops splitting one word's total across case variants — see What Word Frequency Reveals. Sorting stops producing clusters that differ only by an invisible space. Even a slug generator is just a cleanup pipeline with an output format: How URL Slugs Work is the same trim-strip-normalize story pointed at URLs.
Try it yourself
Paste a genuinely messy list — duplicated entries, mixed indentation, blank lines, stray tabs — into the String Trim Lines tool with collapse enabled, then feed the result to the Remove Duplicate Lines tool twice: once with the default strict comparison, once with case-insensitivity and whitespace trimming on, and compare the removed counts. Finish with the Trim Whitespace tool in each of its three modes to see exactly where normalize, trim, and remove diverge on the same input.