Print

Print


On 16 January 2023, Max wrote:

> Does anyone know a tool or hack to help fix a problem at a CSV that's
> causing a "The rows are not all the same number of columns." error when
> trying to import the CSV at a web application?

At a shell, this could help narrow things down:

$ cat foo.csv
one,two,three
two,three,four
three,four,five,six
four,five,six
$ while read line; do echo $line | tr -dc "," | wc -m; done < foo.csv
2
2
3
2

There's no counter to show you which line has the strange number of commas, but 
you could do this after you've eyeballed it and seen most have two:

$ while read line; do echo $line | tr -dc "," | wc -m; done < foo.csv > counts.csv
$ grep -v 2 -c counts.csv

This ignores "quoted,commas,in,one,column" but if there aren't too many of them 
they won't get much in the way.

Bill

--
William Denton
https://www.miskatonic.org/
Librarian, artist and licensed private investigator.
Toronto, Canada
CO₂: 419.29 ppm (Mauna Loa Observatory, 2023-01-15)