cartodb/lib/importer/misc/csv_remove_newlines.py

17 lines
396 B
Python
Raw Normal View History

2020-06-15 10:58:47 +08:00
#!/usr/bin/env python
# Remove newline chars from CSV "cells"
# Input is taken from stdin and output spit to stdout
import csvkit
import sys
reader = csvkit.reader(sys.stdin)
writer = csvkit.writer(sys.stdout)
for row in reader:
for i in range(0, len(row)):
if isinstance(row[i], (str, unicode)):
if "\n" in row[i]:
row[i] = row[i].replace("\n", '')
writer.writerow(row)