Batch tsv to csv conversion

I recently had to convert tables from tsv to csv format and found several ways to do it in this thread from StackOverflow, including the tsv2csv.py Python script below:

import sys
import csv

tabin = csv.reader(sys.stdin, dialect=csv.excel_tab)
commaout = csv.writer(sys.stdout, dialect=csv.excel)
for row in tabin:
    commaout.writerow(row)

Here is a simple wrapper Bash script to run the conversion in batch:

for file in *.tsv
do
    python tsv2csv.py < $file > ${file%.*}.csv
done
Advertisements