Skip to content

Instantly share code, notes, and snippets.

@filimonov
Last active January 6, 2020 16:04
Show Gist options
  • Save filimonov/c3b8e6986e889d67c3b0d4bba9902592 to your computer and use it in GitHub Desktop.
Save filimonov/c3b8e6986e889d67c3b0d4bba9902592 to your computer and use it in GitHub Desktop.
csv2tab
#!/usr/bin/env python
# based on https://unix.stackexchange.com/questions/359832/converting-csv-to-tsv
# usage: zcat file.ssv.gz | csv2tab | clickhouse-client -q 'insert into ... format TSV'
import csv, sys
csv.register_dialect('clickhouse', escapechar="\\", doublequote=0, quotechar='\'',skipinitialspace = 0,delimiter = '\t', quoting=csv.QUOTE_NONE, lineterminator='\n')
# docs: https://docs.python.org/2.7/library/csv.html
csv.writer(sys.stdout, dialect='clickhouse').writerows(csv.reader(sys.stdin, delimiter=';'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment