############################## #!/usr/bin/perl -w #call of CPAN use warnings; use strict; use Cwd; #variables my $i=0; my $directory= getcwd; my $file="options"; #opening output file and adding the header on first row open(FILE, ">>OLTP.txt") or die ("Could not create file OLTP.txt"); print FILE "User script,Serveur Name,Instance Name,Date of script,Serveur Name2,Instance Name2,ADVANCED_COMPRESSION~HEADER,TABLE_COMPRESSION~HEADER,2,count,DATA_DICTIONARY_VIEW,TABLE_OWNER,TABLE_NAME,PARTITION_NAME,COMPRESSION,COMPRESS_FOR,\n"; close FILE; #loop while files are found foreach my $files ( list_files( $directory, 1,$file ) ) { print "File : $files\n"; singlefile($files,$file); } #recursion and list integration sub list_files { my ( $directory, $recurse,$file ) = @_; require File::Spec; # Search in subdirectory or not if ( ( not defined $recurse ) || ( $recurse != 1 ) ) { $recurse = 0; } # verification directory if ( not defined $directory ) { die "No named directory\n"; } # Opening a directory opendir my $fh_rep, $directory or die "Can not open directory $directory\n"; # List files and directories, except (. and ..) my @fic_rep = grep { !/^\.\.?$/ } readdir $fh_rep; # Closing directory closedir $fh_rep or die "Unable to close directory $directory\n"; #fill list with found files my @files; #file or folder? if file: add files to the table. if record: start the recursion foreach my $nom (@fic_rep) { my $mycurrentfile = File::Spec->catdir( $directory, $nom ); if ( -f $mycurrentfile and $mycurrentfile=~ m/$file/ and $mycurrentfile =~ m/\.csv$/i){ push( @files, $mycurrentfile ); } elsif ( -d $mycurrentfile and $recurse == 1 ) { push( @files, list_files($mycurrentfile, $recurse,$file) ); # recursion } } return @files; } ##merge data after filtering sub singlefile { my ( $file,$out) = @_; #open file open(FILE, $file) or die ("error occured while opening file"); #create list from file my @save = ; close(FILE); #empty table rows which do not meet criteria foreach (@save){ $_ = "" unless ($_ =~ m/"ENABLED","OLTP",/ && $_ =~m/^GREP/ ); $_ = "" if ($_ =~m/SYSMAN/|| m/SYS/); chomp $_; } #open output file, add data, close open(FILE, ">>OLTP.txt") or die ("error occured while opening file OLTP.txt"); foreach (@save){ print FILE $_."\n" if ($_); } close(FILE); }