#!/usr/bin/perl -s # csv2tsv - filter comma-separated text (csv) into tab-separated text (tsv) # Steve Kinzler, kinzler@cs.indiana.edu, Jul 03 # http://www.cs.indiana.edu/~kinzler/home.html#unix # NOTE: CSV text may be double-quoted and may include commas in quotes, # TSV is assumed to never be quoted and all tabs are separators use Text::CSV; die "usage: $0 [ file ... ]\n" if $h; $csv = Text::CSV->new; while (<>) { s/[\r\n]*$//; warn("$0: warning, changing tab into 8 spaces in line $. [$_]\n") if s/\t/ /g; warn("$0: skipping line, parse failed in line $. [$_]\n"), next unless $csv->parse($_); print join("\t", $csv->fields()), "\n"; }