我有一个文件管道分隔器。 perl脚本接收文件,通过管道剪切并将每个部分放入bcp脚本,以便稍后bcp到DB表中。 该文件的行是:
**PRISMEXP|11/06/2014|20141106**
***Branch ID|CIF ID|Position ID / Facility ID|Client CS ID|Client Name|Parent CS ID|Parent Name|Credit Rating (PMG rating Facility Type|Maturity Date|End Date|Loan Commitment Amount|Loan Drawn Amount|Loan Overdrawn Amount|Loan Undrawn Amount|Loan Uncommitted Drawn Amount|LOC Commitment Amount|LOC Drawn Amount|LOC Overdrawn Amount|LOC Undrawn Amount|LOC Uncommitted Drawn Amount|LOC Subparticipation|BIS Regulatory Capital|ADAC Product Type Code|ADAC Product Type Name|CS01|Clean Price|ERC|NAIC Code|LGD Region|LGD|Transaction Rating|***
0060|9592014|A001-9592014-0060|82769|NOVARTIS PHARMA SERVICES AG BASEL|51671|NOVARTIS AG|A+|SWITZERLAND|Guarantees
Issued|12/31/2016|12/31/2016|0|0|0|0|0|0|0|0|0|29014.0967835279993469339764885601502052|0||||0|1|550.3648|32541||.32|SUIG|
0060|9592014|A002-9592014-0060|82769|NOVARTIS PHARMA SERVICES AG BASEL|51671|NOVARTIS AG|A+|SWITZERLAND|Standby-L/C|02/28/2020|02/28/2020|0|0|0|0|0|0|0|0|0|277.881539362093140391238650131365795886|0||||0|1|16.13184738|32541||.32|SUIG|
代码是:
open (PRISM, "$infile") or die "Can't open $infile\n";
open (BCP, ">$outfile") or die "Can't create $outfile\n";
while ( <PRISM> ) {
last if /^PRISMEXP/;
next if /^(\s)*$/; # skip blank lines
chomp;
if ( $rowcount > 0 ) {
/^((?:.*?\|){3}?)((?:.*?\|){5}?)((?:.*?\|){14}?)((?:.*?\|){1}?)((?:.*?``\|){1}?)((?:.*?\|){2}?)((?:.*?\|){1}?)((?:.*?\|){1}?)((?:.*?\|){1}?)((?:.*?\|){1}?)((?:.*?\|){1}?)((?:.*?\|){1}?)((?:.*?\|){1}?)(.*?)$/;
$part1 = $1;
$part2 = $2;
$part3 = $3;
$part4 = $4;
$part5 = $5;
$part6 = $6;
$part7 = $7;
$part8 = $8;
$part9 = $9;
$part10 = $10;
$part11 = $11;
$part12 = $12;
$part13 = $13;
$part0 = $file_date . "|";
$part14 = "aaaaa|bbbbb|";
$part15 = "||||";
$part16 = "cccc|X|||";
$part17 = "||";
$part18 = "0|";
# Last column should not have "|"
#chop ($part8);
chop ($part13);
print BCP "$part0$part1$part14$part2$part15$part3$part5$part16$part6$part17$part0$part18$part4$part7$part9$part8$part10$part11$part12$part13\n";
}
++$rowcount;
}
我只在行之间放置空格,以便您可以看到行的开头和结尾。粗体是日期和标题以及两行示例。 问题在于如下。 客户端将添加几行,我现在不需要。 我需要一个perl代码来处理相同数量的字段,即使客户端每天都会增加它们。
知道如何在同一个循环中在perl中执行此操作吗?