GUIDE · DATA
Cleaning CSV-style data at the line level
Comma-separated values are plain text, which makes them tempting to clean with a plain text tool. Some fixes are genuinely safe at the line level; others will quietly corrupt the file. This guide draws the line between the two, shows a safe sequence for the common defects, and explains the one feature of CSV that makes naive line tools dangerous.
What this tool is, and what it is not
This is a line-based text utility. It reads the input, splits it on line breaks, applies one operation to each line, and joins the result. It does not parse CSV. It has no concept of a field, a delimiter, a quoted value or a header row — it sees rows of characters. That makes a whole class of cleaning jobs safe and simple, and it makes another class of jobs unsafe, because a line-based tool cannot see the structure that matters.
Understanding that boundary is the entire skill. Everything below is either “safe, because it operates on rows” or “not safe, because it needs to understand fields”.
The fixes that are safe at the line level
- Trimming padding. Exports frequently add a space after each comma or trailing spaces at the end of a row. Clean spacing removes both, and it cannot change the meaning of a field because it only touches whitespace.
- Removing genuinely empty rows. A blank row in an export is a defect. Remove blank lines deletes it, and because a blank row has no fields to lose, nothing else is affected.
- Removing exact duplicate rows. Concatenating two exports usually duplicates the rows they share. Remove duplicate lines removes exact repeats, keeping the first.
- Sorting rows. If every row is self-contained, sorting the file alphabetically by the first field is safe — and useful for spotting near-duplicates.
- Normalizing case across a whole file. lowercase over a file of email addresses or tags is safe when case genuinely does not matter.
Each of those works because it treats a row as an opaque unit. None of them needs to know where the fields are.
The fixes that need a real spreadsheet
- Quoted fields containing the delimiter. A row such as
\"Smith, John\",42is two fields, not three. A line-based tool cannot know that, so any operation that counts or splits fields will be wrong. - Quoted fields containing a line break. A single logical record can span several physical lines. Removing or sorting lines will cut that record in half.
- Reordering or dropping columns. That requires field awareness.
- Type conversion. Turning text into numbers, dates or currency is a parsing job.
- Encoding repair. If the file was decoded with the wrong character set, the damage is already baked into the characters and a text tool cannot reverse it.
Before and after
A small export with padding, a duplicated header row and a blank row:
name, email , plan Ana, ana@example.com ,pro name, email , plan Ben, ben@example.com, free Ben, ben@example.com, free
After Clean spacing the padding is gone. After Remove blank lines the empty row is gone. After Remove duplicate lines the repeated header and the repeated Ben row are gone:
name, email, plan Ana, ana@example.com, pro Ben, ben@example.com, free
The repeated header is the interesting case. It appeared because the file was built by concatenating two exports, and it is now correctly removed — but only because it was character-for-character identical to the first header. If the second header had been written with different spacing, it would have survived the spacing cleanup differently and then failed to match. Always check the row count before and after.
Delimiters, line endings and the last row
- Line endings. Both Windows-style carriage-return-plus-line-feed and Unix-style line feeds are handled; the output uses a single line feed.
- A missing final line break. Many exports omit it. Nothing here requires it, and nothing here adds it.
- Trailing delimiter. A row ending in a comma looks like it has an extra empty field. This tool does not know that, and will leave it alone — which is the safe behavior, but it also means it will not fix it for you.
- Delimiter choice. Semicolon-separated and tab-separated files behave exactly like comma-separated ones for every operation listed above, because the operations never look at the delimiter.
A safe workflow
- Check for quotes first. If any field is quoted, stop and use a spreadsheet or a script.
- Make a copy of the file before cleaning. The input panel is not saved anywhere.
- Run Clean spacing. Remove the padding that would otherwise hide duplicates.
- Run Remove blank lines. Empty rows go.
- Run Remove duplicate lines. Exact repeats go, including repeated headers.
- Compare the line counts before and after, and confirm the difference matches the number of rows you expected to remove.
- Inspect the first and last rows of the result. Structure errors show up at the boundaries.
Verifying a cleaned file
The counters are the cheapest audit you have. The line count is the row count, so a drop of exactly one after removing a blank row is the expected outcome; a drop of twenty means you deleted data you did not mean to. The character count should fall only by the amount of whitespace removed. If the word count moves after a spacing cleanup, something else happened. These three numbers, read together, catch most mistakes before the file leaves your hands — and if the file is heading into a database, the data-entry normalization guide covers the rules worth applying next.
Frequently asked questions
Can it clean a CSV file that contains commas inside quoted fields?
Not safely. A quoted field can contain the delimiter, so a row is not simply a line of fields. Clean quoted files in a spreadsheet or with a script that parses CSV properly.
Will it remove a duplicated header row?
Yes, if the repeated header is character-for-character identical to the first one after trimming. If the two differ in spacing or case, both survive, which is why cleaning spacing first matters.
Does it change the delimiter or the line endings?
It never touches the delimiter. Line endings are normalized to a single line feed, which is what almost every tool expects.
How do I check that no data was lost?
Compare the line count before and after. The difference should equal the number of rows you intended to remove — blank rows plus exact duplicates. A larger difference means something else was removed.