cartodb-4.42/lib/importer/misc/csv_remove_newlines.py

17 lines
385 B
Python
Raw Normal View History

2024-04-06 13:25:13 +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):
if "\n" in row[i]:
row[i] = row[i].replace("\n", '')
writer.writerow(row)