Hi everyone,
I have got different files in a directory.
Dir1:
File 1
File 2
Sample Input Data:
File 1
$key,$No,$date,$time,$price,$units,$flag
A,1,2010-06-07,93002,10,100,Y
A,1,2010-06-07,153002,10,200,Y
B,2,2010-06-07,93002,10,100,Y
B,2,2010-06-07,153002,10,200,Y
B,2,2010-06-09,93002,10,100,Y
B,2,2010-06-09,153002,10,200,Y
C,3,2010-06-08,113002,10,300,N
A,1,2010-06-08,103002,10,400,N
C,3,2010-06-08,83002,10,500,Y
File 2
$key,$No,$date,$time,$price,$units,$flag
A,1,2010-06-07,083012,10,10,Y
B,2,2010-06-07,163002,10,20,Y
C,3,2010-06-08,123002,10,30,N
A,1,2010-06-08,073002,10,40,N
B,2,2010-06-07,103002,10,50,Y
B,2,2010-06-09,103002,10,50,Y
The output I want is into another directory as follows:
Dir2:
File_A_2010-06-07
A,1,2010-06-07,93002,10,100,Y
A,1,2010-06-07,153002,10,200,Y
A,1,2010-06-07,083012,10,10,Y
File_A_2010-06-08
A,1,2010-06-08,103002,10,400,N
A,1,2010-06-08,073002,10,40,N
File_B_2010-06-07
B,2,2010-06-07,93002,10,100,Y
B,2,2010-06-07,153002,10,200,Y
B,2,2010-06-07,103002,10,50,Y
File_B_2010-06-08
<no data available so nothing>
File_B_2010-06-09
B,2,2010-06-09,93002,10,100,Y
B,2,2010-06-09,153002,10,200,Y
B,2,2010-06-09,103002,10,50,Y
and so on.So for each key values and for each dates, I want the output into different files:
Output 1: For each key value A, for the date 2010-06-07, all the rows from input data should be output into 1 file called File_A_2010-06-07.
Output 2: For each key value A, for date 2010-06-08, all the rows should be output into 1 file called File_A_2010-06-08.
so for each key value A, get files with all dates available in the input files.
Now go to key value B, and then get similar output for each date.
The code I am using is as below:
The issue I am having is that I still dont get the output in one file, It is getting spread across many files.All I need is that for each key, put all data for a particular date into one file.
Could someone help me with this please?
Thanks
J
I have got different files in a directory.
Dir1:
File 1
File 2
Sample Input Data:
File 1
$key,$No,$date,$time,$price,$units,$flag
A,1,2010-06-07,93002,10,100,Y
A,1,2010-06-07,153002,10,200,Y
B,2,2010-06-07,93002,10,100,Y
B,2,2010-06-07,153002,10,200,Y
B,2,2010-06-09,93002,10,100,Y
B,2,2010-06-09,153002,10,200,Y
C,3,2010-06-08,113002,10,300,N
A,1,2010-06-08,103002,10,400,N
C,3,2010-06-08,83002,10,500,Y
File 2
$key,$No,$date,$time,$price,$units,$flag
A,1,2010-06-07,083012,10,10,Y
B,2,2010-06-07,163002,10,20,Y
C,3,2010-06-08,123002,10,30,N
A,1,2010-06-08,073002,10,40,N
B,2,2010-06-07,103002,10,50,Y
B,2,2010-06-09,103002,10,50,Y
The output I want is into another directory as follows:
Dir2:
File_A_2010-06-07
A,1,2010-06-07,93002,10,100,Y
A,1,2010-06-07,153002,10,200,Y
A,1,2010-06-07,083012,10,10,Y
File_A_2010-06-08
A,1,2010-06-08,103002,10,400,N
A,1,2010-06-08,073002,10,40,N
File_B_2010-06-07
B,2,2010-06-07,93002,10,100,Y
B,2,2010-06-07,153002,10,200,Y
B,2,2010-06-07,103002,10,50,Y
File_B_2010-06-08
<no data available so nothing>
File_B_2010-06-09
B,2,2010-06-09,93002,10,100,Y
B,2,2010-06-09,153002,10,200,Y
B,2,2010-06-09,103002,10,50,Y
and so on.So for each key values and for each dates, I want the output into different files:
Output 1: For each key value A, for the date 2010-06-07, all the rows from input data should be output into 1 file called File_A_2010-06-07.
Output 2: For each key value A, for date 2010-06-08, all the rows should be output into 1 file called File_A_2010-06-08.
so for each key value A, get files with all dates available in the input files.
Now go to key value B, and then get similar output for each date.
The code I am using is as below:
Code:
#!/usr/bin/perl
@DT = ("2010-06-07","2010-06-08","2010-06-09","2010-06-10","2010-06-11");
opendir(DIR,"H:/");
my @file= readdir DIR;
closedir DIR;
foreach my $file (@file)
{
open (IN, "H:/".$file);
while($line=<IN>)
{
foreach $DT (@DT)
{ open (OUT, ">>Z:/HFT/bidask/split/".$file.$DT.".txt");
chomp($line);
($key,$no,$date,$time,$price,$units,$flag)=split(/ /,$line);
if($DT eq $date)
{
print $wkn," ",$isin," ",$date," ",$time," ",$price," ",$units," ",$flag, "\n";
print OUT $wkn," ",$isin," ",$date," ",$time," ",$price," ",$units," ",$flag, "\n";
}
}
}
}
close(IN);
close(OUT);
The issue I am having is that I still dont get the output in one file, It is getting spread across many files.All I need is that for each key, put all data for a particular date into one file.
Could someone help me with this please?
Thanks
J