Skip to content

Instantly share code, notes, and snippets.

@Buttonwood
Created April 8, 2016 08:13
Show Gist options
  • Save Buttonwood/b0ea26692ead59407a43f74a1a95824d to your computer and use it in GitHub Desktop.
Save Buttonwood/b0ea26692ead59407a43f74a1a95824d to your computer and use it in GitHub Desktop.
# perl grep.pl case.csv slow-query.log.keys.csv
use IO::File;
open(IN,"<$ARGV[0]");
my $count = 0;
my %fh;
while(<IN>){
chomp;
my @t = split(";");
$count++;
my $file = "./tmp/".$count.".csv";
my $FH = IO::File->new(">$file");
if (defined $FH){
$fh{$t[-1]} = $FH;
}
}
close IN;
open(IN,"<$ARGV[1]");
while(<IN>){
my @t = split(";");
if(exists $fh{$t[2]}){
#my $tmp = $fh{$t[2]};
#print $tmp;
#print $fh{$t[2]} "$_";
$fh{$t[2]}->print("$_");
}
}
close IN;
foreach my $tfh (keys %fh){
$fh{$tfh}->close;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment