我不确定此解决方案是否符合您的需求。但愿如此。这是一个perl
脚本,-
除了前四个和后三个之外,所有字段都用空格包围。它使用非标准模块,Text::CSV_XS
必须使用CPAN
或类似工具安装。
内容infile
:
"Email Address","First Name","Last Name","State","Training","Suppression","Events","MEMBER_RATING","OPTIN_TIME","CLEAN_CAMPAIGN_ID"
"scott@example.com","Scott","Staph","NY","Campaigns and activism","Social Media","Fundraiser",1,"2012-03-08 17:17:42","Training"
内容script.pl
:
use warnings;
use strict;
use Text::CSV_XS;
my $csv = Text::CSV_XS->new({
allow_whitespace => 1,
});
open my $fh, q[<], $ARGV[0] or die qq[Open: $!\n];
while ( my $row = $csv->getline( $fh ) ) {
my $concat = join q[ - ], (@$row)[4 .. @$row-4];
splice @$row, 4, scalar @$row - (3 + 4), $concat;
$csv->print( \*STDOUT, $row );
print qq[\n];
}
像这样运行它:
perl script.pl infile
具有以下输出:
"Email Address","First Name","Last Name",State,"Training - Suppression - Events",MEMBER_RATING,OPTIN_TIME,CLEAN_CAMPAIGN_ID
scott@example.com,Scott,Staph,NY,"Campaigns and activism - Social Media - Fundraiser",1,"2012-03-08 17:17:42",Training