>>>>> "Randall" == Randall Perry <rgp@systame.com> writes:
Randall> Searched through the archives and found this perl one-liner that's supposed
Randall> to replace commas with tabs in text files.
Randall> It worked in as much as it created the new output file; but the output was
Randall> exactly the same as the input.
Randall> Anyone know what's wrong? Or have another way to do this?
Randall> perl -ne 's/^ *"//; s/" *$//; print join("\t", split(/\" *, *\"/))'
Randall> your-table.csv > your-table.tab
CSV is a bear, and best parsed with the Text::CSV module:
use Text::CSV;
my $t = Text::CSV->new;
while (<>) {
chomp;
csv->parse($_);
print join("\t", $csv->columns), "\n";
}
Which correctly handles quotish things, commas in quotes, etc.
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!