fastest way convert tab-delimited file to csv in linux

前端 未结 11 1286
感情败类
感情败类 2020-12-04 07:56

I have a tab-delimited file that has over 200 million lines. What\'s the fastest way in linux to convert this to a csv file? This file does have multiple lines of header i

11条回答
  •  独厮守ぢ
    2020-12-04 08:35

    @ignacio-vazquez-abrams 's python solution is great! For people who are looking to parse delimiters other tab, the library actually allows you to set arbitrary delimiter. Here is my modified version to handle pipe-delimited files:

    import sys
    import csv
    
    pipein = csv.reader(sys.stdin, delimiter='|')
    commaout = csv.writer(sys.stdout, dialect=csv.excel)
    for row in pipein:
      commaout.writerow(row)
    

提交回复
热议问题