Created
February 17, 2015 08:05
-
-
Save radeksimko/b473eb31915522ec3f29 to your computer and use it in GitHub Desktop.
Usage: ./show-invalid-csv-lines.py <filename.csv>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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