基于Linux操作系统环境,通过FTP采集数据文件,解析入库动态生成控制文件.ctl

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_28847617/article/details/80298699
#!/usr/bin/perl
############先读取数据文件的表头##############
my $read_file="VIDEO.csv";
my $write_file="sql.ctl";
open r_file,"< $read_file" or die "not read file$!";
############重定向可以自动创建所需要的文件###############
open w_file,">> $write_file" or die "not touch file $!";


print w_file  "load data\n";

print w_file  "infile $read_file";

#######################

此处省略部分内容

######################

print w_file  "(\n";

my $line=<r_file>;
chomp($line);
##########$line =~ s/,//g;

my @list=split(',',$line);
while(@list)
{
my $end_index=$#list;
#print "现在的最大的索引号是:$end_index";
my $first_ele=shift(@list);
if ($end_index==0)
{
 print w_file $first_ele." char(400)\n".")";
}
else
{
 print w_file $first_ele." char(400),\n";
}

}


生成的结果文件:

(只展示部分控制文件的内容):


(
f1 char(400),
f2 char(400),
f3 char(400),
f4 char(400)
)


猜你喜欢

转载自blog.csdn.net/qq_28847617/article/details/80298699