我有一些错误导出的csv文件。某些包含数字的字段被错误地导出为字符串,小数位用作逗号而不是点。
以下是几个例子:
"GREEN,"15,4",55,"15,5",64,"17,0","18,9",107,145,21,38,
"BLUE","15,1",46,"15,2",51,"11,4","13,5",89,96,25,7,
因此,我想将逗号切换为引号中的数字点,然后从所有数字中删除引号。
有人可以帮帮我吗?
答案 0 :(得分:3)
使用CSV解析器,这变得简单:
#!/usr/bin/perl
use warnings;
use strict;
use Text::CSV_XS;
my $csv = Text::CSV_XS->new( { binary => 1, auto_diag => 1 } );
while ( my $row = $csv->getline( \*DATA ) ) {
s/,/./ for @$row;
$csv->say( \*STDOUT, $row );
}
__DATA__
"GREEN","15,4",55,"15,5",64,"17,0","18,9",107,145,21,38,
"BLUE","15,1",46,"15,2",51,"11,4","13,5",89,96,25,7,
上面的示例使用内联数据使其可以独立运行 - 您可能希望使用输入和输出文件而不是DATA
和STDOUT
。
如果你特别希望保留“字符串”而不是“数字”的引号,那么你可以使用keep_meta_info
或者在需要时重新添加它们。
答案 1 :(得分:0)
,
您可以在"
之间使用此删除 ;WITH tb(sitename,Country,Complete,Reminning,Deleted,Total)AS
(
SELECT 'pcltb.co.in',1,34,0,1,35 UNION
SELECT 'pcltb.co.in',2,48,0,1,35
)
SELECT ISNULL(sitename,'Total') AS sitename,ISNULL(Country,'Total') as Country,SUM(Complete) AS Complete,SUM(Reminning) AS Reminning,SUM(Deleted) AS Deleted,SUM(Total) AS Total
FROM tb
GROUP BY sitename,Country
WITH ROLLUP
HAVING GROUPING(sitename)=GROUPING(Country)
。请参阅演示。