Fix Ragged TSV Rows
"Row 4,812 has 7 fields, expected 6" — the error every TSV consumer eventually throws. The validator tells you where it happens; this page makes the file rectangular so it loads. Start with rejoin: a short row is usually not missing data but half a record, because a field contained a line break and the export wrote it out raw. Gluing the halves back together recovers the row rather than padding a hole that was never there — and the status line tells you how many rows look like that even when you have picked another action.
How to use
- Paste or drop the file. The status line immediately reports the target width and which lines don't match it.
- Check the width source. Header row is right when you trust row one; most common row width is right when the header itself is the broken row.
- Pick an action. Pad-and-truncate produces a loadable file; drop bad rows produces a clean one at the cost of losing data.
- Look at the named lines in the original before you accept the fix — see below for why.
- Copy or download.
Why the file is ragged in the first place
A tab inside a field. The most common cause and the most dangerous, because padding hides it. A free-text field containing a tab splits into two columns, so that row has one extra field and everything after the tab is shifted one column right. Padding or truncating leaves a row full of correctly-counted but wrongly-placed data. If most bad rows have exactly one extra column, this is almost certainly what happened — fix the source instead, or run the file through escape tabs and newlines after re-exporting with quoting on.
A newline inside a field. One logical record becomes two physical lines — one too short, followed by another too short. If your bad line numbers come in adjacent pairs, that's the signature, and the status line counts the rows that fit it whichever action you have selected. Rejoin is the fix: the last field of the short row and the first field of the next are glued back into one cell, and the record comes back whole. Padding both halves instead gives you two broken records where you had one good one.
Genuinely optional trailing columns. Plenty of tools omit trailing empty fields, so a row ending in three empty values gets written short. Here padding is exactly right and completely safe — this is the case the tool is built for.
Concatenated files with different schemas. Two exports appended with cat, one with an extra column. The header row appears twice and widths differ in blocks. Merge TSV files handles this properly by unioning headers; padding does not.
What each action does
Rejoin rows split by a line break walks the file and, whenever a row is short and the following row is short enough to complete it, merges the two — repeatedly, because a field can contain more than one line break. The join character is yours to pick: a space reads best in a spreadsheet, \n as two literal characters keeps the break visible and reversible, and nothing at all is right when the break fell inside a word. Anything still ragged after the merge is padded or truncated and counted separately, so a residual count above zero means something other than a stray newline is wrong.
Pad short, truncate long forces every row to the target width — the file will load anywhere afterwards. Pad short only leaves over-long rows alone, so you keep the extra data and can inspect it. Truncate long only is for the reverse case. Drop bad rows removes anything that doesn't match the target; the count of dropped rows is your data-loss figure, and if it's large the target width is probably wrong.
Padding uses an empty string unless you supply something else. A literal marker like MISSING or \N is often better than an empty cell, because it survives a round trip through a spreadsheet and shows up in stats as a distinct value rather than as a null you might not notice.
FAQ
How do I find out what's in the bad rows before fixing them?
Run the validator — it lists every offending line with its actual column count — then open the file at those lines. Slice rows will pull out a specific range if the file is too big to scroll.
Should I pad or drop?
Pad when the missing fields are genuinely absent (optional trailing columns) — nothing is lost. Drop when a row is corrupt and a half-record is worse than no record, which is usually the case for anything you'll aggregate or join on. Never pad without looking at a couple of the bad rows first.
Can it fix rows split across two lines?
No — rejoining them requires knowing where the record really ended, which the file no longer tells you. If the source can be re-exported with quoting enabled, do that; the parser here reads RFC-4180 quoting, so a quoted newline stays inside its field and the file isn't ragged at all.
What's the awk equivalent?
To find them: awk -F'\t' 'NF!=6 {print NR": "NF}' f.tsv. To pad: awk -F'\t' -v OFS='\t' '{for(i=NF+1;i<=6;i++)$i=""; NF=6; print}' f.tsv. The awk version is faster on huge files; this page is easier when you want to see what you're doing.
Privacy
100% client-side. No upload. See the privacy policy.