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.
In reply to Re: Convert CSV file to TAB delimited
by Utilitarian
in thread Convert CSV file to TAB delimited
by TCM
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |