Remove empty CSV rows and trim whitespace deliberately
Separate empty records from missing cells and meaningful quoted line breaks.
Quick answer. Remove a record only when all its parsed fields are empty. A missing cell in a useful row and a blank physical line inside a quoted note are different. Trimming whitespace is a separate, deliberate change.
Try a file with a known result
Original synthetic teaching data; no customer records. Download the small sample, then load it into the matching tool. Your own files remain in your browser.
Settings for this example
Load the sample in CSV clean with Comma and a header. Preview with every rule off, then enable empty-record removal while leaving Trim off.
Expected results to compare
- The baseline contains 4 data records and 2 columns. The visually blank line belongs inside the first quoted note.
- Empty-record removal deletes only the comma-only record: 1 empty record is removed and 3 data records remain (source records 1, 2, 4 and 5). The identifier 00904 with a missing note stays.
- Enable Trim as well. Exactly 1 cell is trimmed: the edge spaces around Café mug disappear. The internal blank line in the first note remains.
- Preflight reports 1 blank data record and 1 padded cell. The duplicate heuristic skips 00904 because the note is empty.
A source with meaningful edge line breaks or padded fields may require leaving Trim off. This teaching file does not justify deleting raw blank lines from arbitrary CSV.
Open the matching tool →An empty record is different from an empty cell
A CSV can contain a record with no useful fields, a record with one missing value, or a quoted field containing a line break. Those need different treatment. Removing every blank-looking line from the raw text can cut a valid field in half. Parse the file first, then decide whether the whole record is empty.
id,note 00127,"First line Third line" , 00904, 00008," Café mug "
This original teaching example has four data records. The first note contains two line breaks, including a visually blank line. The , record has two empty fields and can be removed with the empty-record rule. The 00904, record contains an identifier and must stay. The final note has two spaces on each edge; trimming is a separate choice.
Preview the rules separately
- Load the source into CSV clean with all rules off. Select the correct delimiter and header setting.
- Enable Remove records whose fields are all empty, then preview. Only the
,record disappears in this example. The multiline note and the missing single note remain. - Enable trim only if edge whitespace has no meaning in your dataset. Preview again and compare the trimmed field examples.
- Review source record numbers, total removed records and the chosen export scope. Download a new CSV while retaining your source.
Inspect empty records and spaces →
Spaces belong to fields until you deliberately remove them
RFC 4180 describes spaces as part of a CSV field. CSV quoting encloses values; it is not a request to trim them. TableMender leaves all spaces unchanged unless you enable its trim rule. That rule uses JavaScript's String.trim(), which removes whitespace and line terminators at the beginning and end, including tabs. It preserves whitespace inside the value.
Trimming can therefore remove a deliberate trailing newline from a note, turn a space-only value into an empty field, or change a padded code. It never converts 00127 into 127, and never collapses internal spaces in Café mug. A field containing an internal line break retains that line break unless it occurs at an edge.
The cleaning order explains the counts
TableMender applies trimming first, empty-record removal second and deduplication last. With trim off, a field holding three spaces is not empty. With trim on, a row of space-only fields becomes eligible for removal. The trimmed-cell count includes cells in subsequently removed rows, so it measures operations rather than only changes in surviving rows. The header is exempt from every cleaning rule.
An empty physical line may parse as a single empty field in a wider file. With empty-record removal explicitly enabled, it can be removed. Other uneven records remain visible and block export. The tool does not add missing delimiters to make a damaged record appear valid.
Use checks that reflect your destination
Compare at least one missing cell, one multiline note, one identifier and the last result record. Search and pagination inspect the result; they do not define the export scope. Choose All result records for the entire cleaned file, or Only records matching the filter for all matches across pages. Formula protection may add an apostrophe to formula-like fields in the exported CSV and is disclosed separately from cleaning. If the result is unsuitable, Restore original preview resets the cleaning rules without overwriting the source.
Edge cases and boundary cases
A record whose fields are only spaces is empty only after trim. With trim off, those spaces are data and the row stays. Enable trim only when padded codes and trailing newlines are accidental in your destination—not because a text editor shows a “blank” line inside a quoted note.
Quoted fields that contain only a line break are not empty records. Removing “blank lines” from the raw file can cut that note in half. Parse first; then apply the empty-record rule to whole records whose every field is empty after optional trim.
Whitespace-only cells in an otherwise useful row must stay if the identifier is present. The teaching row 00904, keeps the product code and a missing note. Deleting it because the note looks blank would drop a real key.
These empty-record rules do not restore values lost to Excel Save As or numeric conversion. If identifiers already lack zeros, cleaning cannot invent them—see Repair versus re-export and Excel Save As CSV pitfalls.
Uneven nonempty widths still block export. An empty physical line may parse as one empty field in a wider table and become removable only when the empty-record rule is on. The tool will not pad missing delimiters to invent a valid width.
Step-by-step troubleshooting
- A “blank” line inside a note disappeared after a text-editor cleanup. That line was field content. Parse first in CSV clean or CSV check & repair. The empty-record rule never looks at raw physical lines.
- 00904 vanished with the comma-only row. You enabled trim and the remaining field was only spaces, or you searched the preview and exported matches. Restore original preview, turn trim off, and compare source record numbers.
- Repair’s Remove blank rows versus Clean’s empty-record rule. On Convert or Repair, Remove blank rows strips fully empty records from the current preview only. On Clean, the named rule is saved in the result and appears in the impact counts. Trim and duplicate rules exist only on Clean.
- Download still blocked after removing blanks. Uneven nonempty records remain. Blank rows never blocked download; mismatched field counts on nonempty rows do.
FAQ grounded in CSV clean
Does empty-record removal delete a missing quantity on an otherwise useful row? No. Every field must be empty after optional trim. A product code with a blank note stays.
Why does the trimmed-cell count include removed rows? Trim runs first. Counts measure operations on the parsed source, not only surviving cells.
Can I get the blanks back? Restore original preview turns every cleaning rule off and rebuilds from the unchanged parsed source. The original file on disk is never overwritten. Cleaned downloads use a -cleaned suffix.
Worked counts on empty-records.csv
Load empty-records.csv in CSV clean with Comma and a header. Leave every rule off for the baseline. The header is source record 1. The comma-only row is source record 3. Source record numbers include the header; they are preview labels and are not written into the download.
| Rules | What stays |
|---|---|
| All rules off | 4 data records. Source records 1–5 remain. The visually blank line is inside the first quoted note, not a fifth data row. |
| Empty-record removal only | Removes 1 empty record (source record 3, the comma-only row). 3 data records remain: source records 1, 2, 4 and 5. Identifier 00904 with a missing note stays. The first note still contains First line, two line breaks, then Third line. |
| Trim only | 4 data records stay, including the comma-only row. Exactly 1 cell is trimmed: source record 5, field 2, Café mug becomes Café mug. The internal blank line in the first note is not edge whitespace, so it stays. |
| Trim then empty-record removal | Same 1 empty record removed and the same 1 trimmed cell. 3 data records remain. Trim runs first; the trimmed-cell count includes cells in subsequently removed rows when those rows had padding. This file’s removed row had no padding, so the trim count is still 1. |
Restore original preview turns every rule off and rebuilds from the unchanged parsed source. Undo last change restores the previous file, paste, sample or rules. The -cleaned download does not replace the sample.
What preflight counts on empty-records.csv
After Preview, with every cleaning rule still off, preflight reports 1 blank data record. The how-to link on that row is this page. The whitespace row reports 1 data cell with leading or trailing spaces in column 2 (the padded Café mug). That how-to link is also this page. Neither row deletes anything; they name optional rules.
The identifier row warns: leading zeros in column 1 (3 cells: 00127, 00904 and 00008). The how-to link on that row opens Keep leading zeros. Cleaning does not invent padding. Number on id is blocked by those zeros; the comma-only row counts as 1 blank numeric cell and is not a reason to mark the column Number.
The duplicate-row check skips 1 incomplete row — 00904 with an empty note — and reports no exact whole-row duplicates among complete rows. A missing note is not a duplicate of the fully empty record. Duplicate removal with id as the key finds no group: each identifier appears once. See duplicate keys.
The formula-like row stays clear. Accented Café is not a replacement character. This UTF-8 sample is not an encoding problem. Matching tools: CSV clean, then CSV to Excel once the empty record is gone if you need a text workbook, and CSV check & repair when quoting hid the blank line.
Sources:
Examples are original teaching data. Tool-specific behavior describes this version of TableMender; software interfaces can vary by version.