in reply to Convert CSV file to TAB delimited
becomes"perl -e ' $sep=","; while(<>) { s/\Q$sep\E/\t/g; print $_; } warn "Ch +anged $sep to tab on $. lines\n" ' csvfile.csv > tabfile.tab"
However what do you do with lines such as#!/usr/bin/perl use strict; use warnings; my $sep=","; open (my $csv_file , "<" , 'csvfile.csv'); open (my $tab_file , ">" , 'tabfile.tab'); while(<$csv_file>) { s/\Q$sep\E/\t/g; print $tab_file, $_; } warn "Changed $sep to tab on $. lines\n"
When processing CSV's there are all kinds of edge cases, so use a module that has looked at these issues already rather than ending up with unsupportable code, I would suggest Text::CSV."Monster, The Cookie", "123 Sesame St, TV land"
You can open a new csv object with a different separator and just write it without having to contemplate cases like the above.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Convert CSV file to TAB delimited
by TCM (Acolyte) on Sep 23, 2010 at 13:27 UTC | |
by Tux (Canon) on Sep 23, 2010 at 14:33 UTC | |
by TCM (Acolyte) on Sep 23, 2010 at 17:31 UTC |