我的CSV文件格式如下,我在网上下载并需要解析它。我希望能够摆脱“单位”栏目。我该怎么做呢?我希望能够在解析文件时执行此操作,而不是将其复制到其他文件,因为文件非常大。谢谢!
<radio>,<mcc>,<net>,<area>,<cell>,<unit>,<lon>,<lat>,<range>,<samples>,<changeable>,<created>,<updated>,<averageSignal>
UMTS,262,2,801,86355,,13.28527,52.521711,37,7,1,1282569574,1300175362,-91GSM,262,2,801,1795,,13.276605,52.525348,5714,9,1,1282569574,1300175362,-87
答案 0 :(得分:-1)
IntegrationFLow
逐行读取STDIN,并随时打印,因此您不需要大量内存。
您可以通过就地编辑来完成,但是您要测试它以确保它首先令人满意地工作。你可以通过设置#!/usr/bin/env perl
use strict;
use warnings;
my $col_to_delete = '<unit>';
chomp ( my @header = split /,/, <> );
my @newheader = grep { not $_ eq $col_to_delete } @header;
print join (",", @newheader),"\n";
while ( <> ) {
chomp;
my %row;
@row{@header} = split /,/;
print join (",", @row{@newheader}),"\n";
}
来做到这一点,但实际上你最好不要创建两个文件,因为它很容易让人意外地破坏它们。