因此,我從sybase數據庫輸出中獲取此輸出。 我需要取出雙引號並向表中插入一些行定義。我客串Perl是做perl將字符串插入文件後匹配正則表達式
"NO Comm","-"
"INVESTMENT","29541","3860237","0","ANEW","(null)","BP ","frantzla","A"
"DERIVS","110000","2875587","0","ANEW","0","BP ","frantzla","A"
"DERIVS","4089","1185810","0","IBKD","0","BP ","unsalr ","A"
"COMMERCE","705","41185","0","ANEW","(null)","BP ","madiganj","A"
"FIRST","504","236","0","ANEW","0","CPS ","kilkenki","A"
" ","-"
"Opera Pending","-"
"FIRST","827921","23565575","20699","ANEW","2.5","CPS ","kilkenki","A"
"INC","218780","3596112","5472","ANEW","2.5","CPS ","madiganj","A"
" ","-"
"ETC Pending","-"
"BANK , PITTSBURGH","251508","10803056","1258","IBKD","0.5","CPS ","dennyad ","A"
"SYDNEY","4500","178173","45","IBKD","1","CPS ","dennyad ","A"
" ","-"
"Confirmed Booking","-"
"MOTHER FUND","22400","1187584","1781","IBKD","15","BP ","crouzejo","A"
"ASSET MANAGEMENT, SGIIC, S.","45010","614834","922","IBKD","15","BP ","ruizdemi","A"
一旦我走「雙引號」我拿出所有的結了一個「 - 」一些表名的工具後,他們的權利。 我需要在talbe名稱後面放置一個標題來定義行。所以我所要做的幾乎都是perl腳本碰到一個「\ w + \ - 」的常年時間,它所需要做的就是將此行插入到下一行。
Client , Shares , Notional, TotalComm, Status, Comm, CommType, Owner, TradingBasis
它是它下面的值的標題。 它打印出標題 - 但不是整個報告。 這是一個CSV文件,我需要將這些標題放在表格上。
#!/usr/bin/perl
use strict;
use warnings;
open my $fhIn, '<', 'today.txt' or die $!;
my $add_trip = "Client , Shares , Notional, TotalComm, Status, Comm, CommType, Owner, TradingBasis" ;
while (<$fhIn>) {
my $print_flag = 0 ;
tr/\"//d;
if(/\w+\,-/) {
$print_flag = 1 ;
if($print_flag) {
print "$add_trip\n" ;
} else { print $_ ; }
}
}
結果 - 該表不是隻打印我要插入的行打印:
Client , Shares , Notional, TotalComm, Status, Comm, CommType, Owner, TradingBasis
Client , Shares , Notional, TotalComm, Status, Comm, CommType, Owner, TradingBasis
Client , Shares , Notional, TotalComm, Status, Comm, CommType, Owner, TradingBasis
Client , Shares , Notional, TotalComm, Status, Comm, CommType, Owner, TradingBasis
我需要更多的東西是這樣的:
ETC Pending,-
Client , Shares , Notional, TotalComm, Status, Comm, CommType, Owner, TradingBasis
BANK , PITTSBURGH,251508,10803056,1258,IBKD,0.5,CPS ,dennyad ,A
SYDNEY,4500,178173,45,IBKD,1,CPS ,dennyad ,A
,-
Confirmed Booking,-
Client , Shares , Notional, TotalComm, Status, Comm, CommType, Owner, TradingBasis
MOTHER FUND,22400,1187584,1781,IBKD,15,BP ,crouzejo,A
ASSET MANAGEMENT, SGIIC, S.,45010,614834,922,IBKD,15,BP ,ruizdemi,A
獎金 - 這將是在劇本全部完成後擺脫'' - ''是很好的 - 從csv文件中刪除它們會更好,但我需要它們將頭部放入int中,所以我無法擺脫它們,直到我知道標題桌子在。