Skip to content

Instantly share code, notes, and snippets.

@radeksimko
Created February 17, 2015 08:05
Show Gist options
  • Select an option

  • Save radeksimko/b473eb31915522ec3f29 to your computer and use it in GitHub Desktop.

Select an option

Save radeksimko/b473eb31915522ec3f29 to your computer and use it in GitHub Desktop.
Usage: ./show-invalid-csv-lines.py <filename.csv>
#!/usr/bin/env python
import sys
DELIMITER = '|'
line_number = 0
with open(sys.argv[1], 'r') as fh:
header = fh.readline()
delim_in_header = header.count(DELIMITER)
line_number += 1
for line in fh.readlines():
line_number += 1
delim_in_line = line.count(DELIMITER)
if delim_in_header != delim_in_line:
print '%d: Wrong number of delimiters (%d), %d expected!' % (
line_number, delim_in_line, delim_in_header)
print line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment