#! /opt/local/bin/perl -w # Part 1: Write all of the filenames to Index.txt to be able to input names as an array # open directory1, ">./index.txt" or die "Could not create file: $!\n"; use File::Find; my @all_file_names; find sub { return if -d; push @all_file_names, $File::Find::name; }, '*my directory*'; for my $path ( @all_file_names ) { select directory1; print "$path\n"; } print STDERR "contents of directory written \n"; close directory1; ################################################## # Part 2: Open & Read Contract List # ################################################## my $filename = 'index.txt'; open my $fh, $filename or die "Couldn't read '$filename': $!"; #chomp @ARGV = <$fh>; print "Processing $_" for @ARGV; ################################################## # Part 3: Read in the contracts and search for keywords # ################################################## open Contract1a, ">./test.txt" or die "Could not create file: $!\n"; @contracts = @ARGV; $linescount = 20; #set how many lines after the match you'd like to pull; foreach (@contracts) { open Contract1, "<./$_ \n"; @lines = ; close Contract1; my $contents = join "", @lines; @all = undef; shift @all; while ($contents =~ m/Management Fees/i) { if ($contents =~ m/(\n.*Management Fees(.*\n){$linescount})/i) { push (@all, "$1\n"); print STDERR "$1\n"; $contents =~ s/Management Fees//i; } } select Contract1a; print join("\n",(@all)); print "\n"; } print STDERR "...Contract1 match complete.\n\n"; close Contract1a;>